From 4e7abfcae05ac4d9f849aeed3b0a994b369a6ea6 Mon Sep 17 00:00:00 2001 From: likevy Date: Mon, 7 Sep 2026 16:48:20 +0200 Subject: [PATCH 01/25] fix(fab): align MD3 variants and interaction states Add surface and branded variants, apply web hover elevation, and prevent hidden FABs from retaining focus or actions. Keep large icons at 36dp. BREAKING CHANGE: Replace tonalPrimary, tonalSecondary, and tonalTertiary with primaryContainer, secondaryContainer, and tertiaryContainer. The old variant names are removed without aliases. --- example/src/Examples/FABExample.tsx | 37 +- src/components/FAB/Extended.tsx | 9 +- src/components/FAB/FAB.tsx | 9 +- src/components/FAB/Menu.tsx | 33 +- src/components/FAB/Shell.tsx | 76 +++- src/components/FAB/tokens.ts | 16 +- src/components/FAB/utils.ts | 2 +- src/components/__tests__/FAB.test.tsx | 145 +++++- src/components/__tests__/FABUtils.test.tsx | 47 +- .../__tests__/__snapshots__/FAB.test.tsx.snap | 430 ++++++++++++++++++ .../__snapshots__/FABExtended.test.tsx.snap | 1 + .../__snapshots__/FABMenu.test.tsx.snap | 1 + 12 files changed, 749 insertions(+), 57 deletions(-) diff --git a/example/src/Examples/FABExample.tsx b/example/src/Examples/FABExample.tsx index 09ce39aa14..3937dcdf4c 100644 --- a/example/src/Examples/FABExample.tsx +++ b/example/src/Examples/FABExample.tsx @@ -34,9 +34,11 @@ const variants: FabColor[] = [ 'primary', 'secondary', 'tertiary', - 'tonalPrimary', - 'tonalSecondary', - 'tonalTertiary', + 'primaryContainer', + 'secondaryContainer', + 'tertiaryContainer', + 'surface', + 'branded', 'custom', ]; @@ -91,7 +93,7 @@ const FABExample = () => { const { colors } = useTheme(); const insets = useSafeAreaInsets(); - const [variant, setVariant] = React.useState('tonalPrimary'); + const [variant, setVariant] = React.useState('primaryContainer'); const activeVariant = variant === 'custom' ? undefined : variant; const activeContainerColor = variant === 'custom' ? CUSTOM_CONTAINER_COLOR : undefined; @@ -138,12 +140,29 @@ const FABExample = () => { v !== 'surface' && v !== 'branded') + : variants + } value={variant} onChange={setVariant} /> - + { + if ( + nextType === 'menu' && + (variant === 'surface' || variant === 'branded') + ) { + setVariant('primaryContainer'); + } + setType(nextType); + }} + /> { {type === 'icon' && ( { alignment={position} trigger={{ icon: 'pencil', - variant: activeVariant, + variant: + activeVariant === 'surface' || activeVariant === 'branded' + ? undefined + : activeVariant, containerColor: activeContainerColor, size, visible: showFab, diff --git a/src/components/FAB/Extended.tsx b/src/components/FAB/Extended.tsx index 15a971f457..a5e4f28f3c 100644 --- a/src/components/FAB/Extended.tsx +++ b/src/components/FAB/Extended.tsx @@ -39,7 +39,12 @@ export type Props = { */ label: string; /** - * Role-color preset. Defaults to `tonalPrimary`. + * Role-color preset. Defaults to `primaryContainer`. + * Choose `primary`, `primaryContainer`, `secondary`, `secondaryContainer`, + * `tertiary`, `tertiaryContainer`, `surface`, or `branded`. + * `surface` and `branded` use `surfaceContainerHigh`; `surface` uses primary + * content, while `branded` uses on-surface content. Pass a custom icon source + * to preserve brand artwork colors. */ variant?: Variant; /** @@ -167,7 +172,7 @@ export type Props = { const Extended = ({ icon, label, - variant = 'tonalPrimary', + variant = 'primaryContainer', containerColor, contentColor, size = 'default', diff --git a/src/components/FAB/FAB.tsx b/src/components/FAB/FAB.tsx index 5b92548c47..5a02589adf 100644 --- a/src/components/FAB/FAB.tsx +++ b/src/components/FAB/FAB.tsx @@ -21,7 +21,12 @@ export type Props = { */ icon: IconSource; /** - * Role-color preset. Defaults to `tonalPrimary`. + * Role-color preset. Defaults to `primaryContainer`. + * Choose `primary`, `primaryContainer`, `secondary`, `secondaryContainer`, + * `tertiary`, `tertiaryContainer`, `surface`, or `branded`. + * `surface` and `branded` use `surfaceContainerHigh`; `surface` uses primary + * content, while `branded` uses on-surface content. Pass a custom icon source + * to preserve brand artwork colors. */ variant?: Variant; /** @@ -130,7 +135,7 @@ export type Props = { */ const FAB = ({ icon, - variant = 'tonalPrimary', + variant = 'primaryContainer', size = 'default', visible = true, onPress, diff --git a/src/components/FAB/Menu.tsx b/src/components/FAB/Menu.tsx index 77f6e0b0bc..476e28aa8b 100644 --- a/src/components/FAB/Menu.tsx +++ b/src/components/FAB/Menu.tsx @@ -50,13 +50,15 @@ export type MenuItemProps = { testID?: string; }; +type MenuVariant = Exclude; + export type MenuTriggerProps = { /** * Icon displayed in the trigger FAB (and cross-faded to `closeIcon` when * the menu is open). */ icon: IconSource; - variant?: Variant; + variant?: MenuVariant; size?: Size; containerColor?: ColorValue; contentColor?: ColorValue; @@ -116,24 +118,30 @@ export type MenuProps = { * The close button is always the saturated role color; items are always the * tonal (container) role color. */ -const getCloseVariant = (triggerVariant: Variant): Variant => { - if (triggerVariant === 'primary' || triggerVariant === 'tonalPrimary') { +const getCloseVariant = (triggerVariant: MenuVariant): Variant => { + if (triggerVariant === 'primary' || triggerVariant === 'primaryContainer') { return 'primary'; } - if (triggerVariant === 'secondary' || triggerVariant === 'tonalSecondary') { + if ( + triggerVariant === 'secondary' || + triggerVariant === 'secondaryContainer' + ) { return 'secondary'; } return 'tertiary'; }; -const getItemsVariant = (triggerVariant: Variant): Variant => { - if (triggerVariant === 'primary' || triggerVariant === 'tonalPrimary') { - return 'tonalPrimary'; +const getItemsVariant = (triggerVariant: MenuVariant): Variant => { + if (triggerVariant === 'primary' || triggerVariant === 'primaryContainer') { + return 'primaryContainer'; } - if (triggerVariant === 'secondary' || triggerVariant === 'tonalSecondary') { - return 'tonalSecondary'; + if ( + triggerVariant === 'secondary' || + triggerVariant === 'secondaryContainer' + ) { + return 'secondaryContainer'; } - return 'tonalTertiary'; + return 'tertiaryContainer'; }; // Per-item delay used by the stagger. Compose uses a single SlowEffects-driven @@ -306,7 +314,7 @@ const MenuItem = ({ }; type MorphingTriggerProps = { - triggerVariant: Variant; + triggerVariant: MenuVariant; closeVariant: Variant; triggerContainerColor?: ColorValue; triggerContentColor?: ColorValue; @@ -453,6 +461,7 @@ const MorphingTrigger = ({ ]} > { const theme = useInternalTheme(themeOverrides); + const [hovered, setHovered] = React.useState(false); + const [pressed, setPressed] = React.useState(false); + const [focused, setFocused] = React.useState(false); + const touchableRef = React.useRef(null); + + const hasHandler = hasTouchHandler({ onPress, onLongPress, onPressOut }); + + // Explicit elevations (including flat menu items) keep their own treatment. + const resolvedElevation = + elevation ?? + (Platform.OS === 'web' && visible && hasHandler + ? pressed + ? Tokens.stateElevation.pressed + : focused + ? Tokens.stateElevation.focus + : hovered + ? Tokens.stateElevation.hover + : Tokens.stateElevation.enabled + : Tokens.stateElevation.enabled); const dimensions = React.useMemo( () => getDimensions({ theme, size, shape, iconSize, leading, trailing }), @@ -315,24 +334,33 @@ const Shell = ({ [borderRadius, containerBg] ); - const hasHandler = hasTouchHandler({ onPress, onLongPress, onPressOut }); - // `scope: 'within'`: the ring is drawn on the clip view below, not the // inner `TouchableRipple` that actually receives focus. On web the shared // stylesheet hides the browser's own outline there, so only the clip view's // ring shows, or only the outline in a browser without `:has()`. // - // Off when `disabled` or without a touch handler: the inner TouchableRipple - // is then a plain View, and a focused one unmounts without a blur reaching - // the hook. The public FAB has no `disabled`, so dropping the handlers is how - // an app turns it off. + // Off when `disabled`, without a touch handler or while hidden: the inner + // TouchableRipple then can't be pressed, and a focused one unmounts without + // a blur reaching the hook. The public FAB has no `disabled`, so dropping + // the handlers is how an app turns it off. const { target: focusTarget, ring: focusRing } = useFocusRing( - disabled || !hasHandler, + disabled || !hasHandler || !visible, theme.colors.secondary, 'outward', 'within' ); + React.useEffect(() => { + if (!visible || !hasHandler) { + if (Platform.OS === 'web') { + touchableRef.current?.blur(); + } + setHovered(false); + setPressed(false); + setFocused(false); + } + }, [visible, hasHandler]); + // Without a handler the touchable drops the button role, and on web that // renders role="presentation", which can't carry a name. A labelled // icon-only FAB that does nothing is an image there, named by its label. @@ -348,6 +376,7 @@ const Shell = ({ return ( {overlay} setHovered(true)} + onHoverOut={() => setHovered(false)} + onPressIn={() => setPressed(true)} + onPressOut={(event) => { + setPressed(false); + onPressOut?.(event); + }} + onFocus={(event) => { + setFocused(true); + focusTarget.onFocus?.(event); + }} + onBlur={() => { + setFocused(false); + focusTarget.onBlur?.(); + }} aria-label={ariaLabel} role={isWebImage ? 'img' : 'button'} aria-checked={ariaChecked} diff --git a/src/components/FAB/tokens.ts b/src/components/FAB/tokens.ts index 4188bc340a..bf7a8d95e7 100644 --- a/src/components/FAB/tokens.ts +++ b/src/components/FAB/tokens.ts @@ -9,9 +9,11 @@ export type Variant = | 'primary' | 'secondary' | 'tertiary' - | 'tonalPrimary' - | 'tonalSecondary' - | 'tonalTertiary'; + | 'primaryContainer' + | 'secondaryContainer' + | 'tertiaryContainer' + | 'surface' + | 'branded'; export type Size = 'default' | 'medium' | 'large'; @@ -65,18 +67,20 @@ const stateElevation = { } as const satisfies Record; const variants = { + surface: { container: 'surfaceContainerHigh', content: 'primary' }, + branded: { container: 'surfaceContainerHigh', content: 'onSurface' }, primary: { container: 'primary', content: 'onPrimary' }, secondary: { container: 'secondary', content: 'onSecondary' }, tertiary: { container: 'tertiary', content: 'onTertiary' }, - tonalPrimary: { + primaryContainer: { container: 'primaryContainer', content: 'onPrimaryContainer', }, - tonalSecondary: { + secondaryContainer: { container: 'secondaryContainer', content: 'onSecondaryContainer', }, - tonalTertiary: { + tertiaryContainer: { container: 'tertiaryContainer', content: 'onTertiaryContainer', }, diff --git a/src/components/FAB/utils.ts b/src/components/FAB/utils.ts index cd894f048d..9c1a0eb72d 100644 --- a/src/components/FAB/utils.ts +++ b/src/components/FAB/utils.ts @@ -19,7 +19,7 @@ export type ResolvedColors = { */ export const resolveColors = ({ theme, - variant = 'tonalPrimary', + variant = 'primaryContainer', containerColor, contentColor, }: { diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 0a6bc8f082..6d82b7b46c 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -12,8 +12,14 @@ import { fireEvent, userEvent } from '@testing-library/react-native'; import * as Reanimated from 'react-native-reanimated'; import PaperProvider from '../../core/PaperProvider'; +import { getTheme } from '../../core/theming'; import { render, screen } from '../../test-utils'; +import { + androidElevationLevels, + shadow, +} from '../../theme/tokens/sys/elevation'; import FAB from '../FAB'; +import Shell from '../FAB/Shell'; import Tooltip from '../Tooltip/Tooltip'; jest.mock('react-native-reanimated', () => { @@ -29,6 +35,10 @@ jest.mock('react-native-reanimated', () => { }; }); +afterEach(() => { + jest.restoreAllMocks(); +}); + it('renders FAB with default props', async () => { const tree = (await render()).toJSON(); expect(tree).toMatchSnapshot(); @@ -49,16 +59,16 @@ it('renders FAB with tertiary variant', async () => { expect(tree).toMatchSnapshot(); }); -it('renders FAB with tonalSecondary variant', async () => { +it('renders FAB with secondaryContainer variant', async () => { const tree = ( - await render() + await render() ).toJSON(); expect(tree).toMatchSnapshot(); }); -it('renders FAB with tonalTertiary variant', async () => { +it('renders FAB with tertiaryContainer variant', async () => { const tree = ( - await render() + await render() ).toJSON(); expect(tree).toMatchSnapshot(); }); @@ -273,3 +283,130 @@ describe('without a touch handler', () => { }); }); }); + +it.each(['icon', 'extended'] as const)( + 'applies web hover elevation to the %s FAB and restores it after press and exit', + async (type) => { + jest.replaceProperty(Platform, 'OS', 'web'); + const onPress = jest.fn(); + await render( + type === 'icon' ? ( + + ) : ( + + ) + ); + const fab = screen.getByTestId('floating-action-button'); + const container = screen.getByTestId('floating-action-button-container'); + const theme = getTheme(); + const [restingShadow] = shadow(3, theme.colors.shadow); + const [hoverShadow] = shadow(4, theme.colors.shadow); + + expect(container).toHaveStyle(restingShadow); + await fireEvent(fab, 'hoverIn'); + expect(container).toHaveStyle(hoverShadow); + await fireEvent(fab, 'pressIn'); + expect(container).toHaveStyle(restingShadow); + await fireEvent(fab, 'pressOut'); + expect(container).toHaveStyle(hoverShadow); + await fireEvent(fab, 'hoverOut'); + expect(container).toHaveStyle(restingShadow); + } +); + +it('keeps an explicit shell elevation of zero on hover', async () => { + jest.replaceProperty(Platform, 'OS', 'web'); + await render( {}} elevation={0} />); + await fireEvent(screen.getByTestId('fab-shell'), 'hoverIn'); + const [flatShadow] = shadow(0, getTheme().colors.shadow); + expect(screen.getByTestId('fab-shell-container')).toHaveStyle(flatShadow); +}); + +it('does not enable a FAB without an action when adding interaction handlers', async () => { + await render(); + expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); +}); + +it('hides an invisible FAB from accessibility and disables its action', async () => { + const onPress = jest.fn(); + await render( + + ); + expect(screen.queryByRole('button', { name: 'Create' })).toBeNull(); + const fab = screen.getByTestId('floating-action-button', { + includeHiddenElements: true, + }); + expect(fab).toBeDisabled(); + await userEvent.press(fab); + expect(onPress).not.toHaveBeenCalled(); +}); + +it('clears interaction elevation when a FAB is hidden and shown again', async () => { + jest.replaceProperty(Platform, 'OS', 'web'); + const onPress = jest.fn(); + const { rerender } = await render(); + await fireEvent(screen.getByTestId('floating-action-button'), 'hoverIn'); + await rerender(); + await rerender(); + const [restingShadow] = shadow(3, getTheme().colors.shadow); + expect(screen.getByTestId('floating-action-button-container')).toHaveStyle( + restingShadow + ); +}); + +it('keeps the menu trigger at its existing elevation on web', async () => { + jest.replaceProperty(Platform, 'OS', 'web'); + await render( + {}} + trigger={{ icon: 'plus', testID: 'menu-trigger', onPress: () => {} }} + items={[ + { label: 'First', onPress: () => {} }, + { label: 'Second', onPress: () => {} }, + ]} + /> + ); + await fireEvent(screen.getByTestId('fab-shell'), 'hoverIn'); + const [restingShadow] = shadow(3, getTheme().colors.shadow); + expect(screen.getByTestId('fab-shell-container')).toHaveStyle(restingShadow); +}); + +it.each(['ios', 'android'] as const)( + 'keeps native elevation unchanged on hover on %s', + async (platform) => { + jest.replaceProperty(Platform, 'OS', platform); + await render( {}} />); + await fireEvent(screen.getByTestId('floating-action-button'), 'hoverIn'); + const [restingShadow] = shadow(3, getTheme().colors.shadow); + expect(screen.getByTestId('floating-action-button-container')).toHaveStyle( + platform === 'android' + ? { elevation: androidElevationLevels[3] } + : restingShadow + ); + } +); + +it('restores the resting elevation when a hovered FAB is hidden or its action is removed', async () => { + jest.replaceProperty(Platform, 'OS', 'web'); + const onPress = jest.fn(); + const { rerender } = await render(); + await fireEvent(screen.getByTestId('floating-action-button'), 'hoverIn'); + await rerender(); + const [restingShadow] = shadow(3, getTheme().colors.shadow); + expect( + screen.getByTestId('floating-action-button-container', { + includeHiddenElements: true, + }) + ).toHaveStyle(restingShadow); + await rerender(); + expect(screen.getByTestId('floating-action-button-container')).toHaveStyle( + restingShadow + ); +}); diff --git a/src/components/__tests__/FABUtils.test.tsx b/src/components/__tests__/FABUtils.test.tsx index 9389ccd78d..75a0068ed5 100644 --- a/src/components/__tests__/FABUtils.test.tsx +++ b/src/components/__tests__/FABUtils.test.tsx @@ -1,10 +1,45 @@ import { describe, expect, it } from '@jest/globals'; -import { LightTheme } from '../../theme/schemes'; +import { DarkTheme, LightTheme } from '../../theme/schemes'; import { getDimensions, resolveColors } from '../FAB/utils'; describe('resolveColors', () => { - it('returns theme colors for default variant (tonalPrimary)', () => { + it.each([false, true])( + 'resolves every MD3 color variant (dark=%s)', + (dark) => { + const theme = dark ? DarkTheme : LightTheme; + const variants = { + primary: ['primary', 'onPrimary'], + primaryContainer: ['primaryContainer', 'onPrimaryContainer'], + secondary: ['secondary', 'onSecondary'], + secondaryContainer: ['secondaryContainer', 'onSecondaryContainer'], + tertiary: ['tertiary', 'onTertiary'], + tertiaryContainer: ['tertiaryContainer', 'onTertiaryContainer'], + surface: ['surfaceContainerHigh', 'primary'], + branded: ['surfaceContainerHigh', 'onSurface'], + } as const; + + const variantNames = [ + 'primary', + 'primaryContainer', + 'secondary', + 'secondaryContainer', + 'tertiary', + 'tertiaryContainer', + 'surface', + 'branded', + ] as const; + for (const variant of variantNames) { + const [container, content] = variants[variant]; + expect(resolveColors({ theme, variant })).toEqual({ + container: theme.colors[container], + content: theme.colors[content], + }); + } + } + ); + + it('returns theme colors for default variant (primaryContainer)', () => { const colors = resolveColors({ theme: LightTheme }); expect(colors).toEqual({ container: LightTheme.colors.primaryContainer, @@ -36,10 +71,10 @@ describe('resolveColors', () => { }); }); - it('returns theme colors for tonalSecondary variant', () => { + it('returns theme colors for secondaryContainer variant', () => { const colors = resolveColors({ theme: LightTheme, - variant: 'tonalSecondary', + variant: 'secondaryContainer', }); expect(colors).toEqual({ container: LightTheme.colors.secondaryContainer, @@ -47,10 +82,10 @@ describe('resolveColors', () => { }); }); - it('returns theme colors for tonalTertiary variant', () => { + it('returns theme colors for tertiaryContainer variant', () => { const colors = resolveColors({ theme: LightTheme, - variant: 'tonalTertiary', + variant: 'tertiaryContainer', }); expect(colors).toEqual({ container: LightTheme.colors.tertiaryContainer, diff --git a/src/components/__tests__/__snapshots__/FAB.test.tsx.snap b/src/components/__tests__/__snapshots__/FAB.test.tsx.snap index f469bb2d57..48e7f74601 100644 --- a/src/components/__tests__/__snapshots__/FAB.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/FAB.test.tsx.snap @@ -1871,6 +1871,221 @@ exports[`renders FAB with secondary variant 1`] = ` `; +exports[`renders FAB with secondaryContainer variant 1`] = ` + + + + + + + plus + + + + + +`; + exports[`renders FAB with tertiary variant 1`] = ` `; +exports[`renders FAB with tertiaryContainer variant 1`] = ` + + + + + + + plus + + + + + +`; + exports[`renders FAB with tonalSecondary variant 1`] = ` Date: Fri, 11 Sep 2026 11:16:44 +0200 Subject: [PATCH 02/25] fix(fab): address review feedback Remove the surface preset and static elevation override. Apply hover elevation across platforms and restore focus when hiding a focused FAB. Separate hidden and disabled semantics, and rewrite the migration guide around v5 consumer changes. --- example/src/Examples/FABExample.tsx | 15 +- src/components/FAB/Extended.tsx | 5 - src/components/FAB/FAB.tsx | 5 - src/components/FAB/Menu.tsx | 3 +- src/components/FAB/Shell.tsx | 69 ++++--- src/components/FAB/tokens.ts | 3 +- src/components/__tests__/FAB.test.tsx | 182 +++++++++++------- src/components/__tests__/FABUtils.test.tsx | 4 +- .../__snapshots__/FABMenu.test.tsx.snap | 7 +- 9 files changed, 167 insertions(+), 126 deletions(-) diff --git a/example/src/Examples/FABExample.tsx b/example/src/Examples/FABExample.tsx index 3937dcdf4c..f878c61b24 100644 --- a/example/src/Examples/FABExample.tsx +++ b/example/src/Examples/FABExample.tsx @@ -37,7 +37,6 @@ const variants: FabColor[] = [ 'primaryContainer', 'secondaryContainer', 'tertiaryContainer', - 'surface', 'branded', 'custom', ]; @@ -141,9 +140,7 @@ const FABExample = () => { v !== 'surface' && v !== 'branded') - : variants + type === 'menu' ? variants.filter((v) => v !== 'branded') : variants } value={variant} onChange={setVariant} @@ -154,10 +151,7 @@ const FABExample = () => { options={types} value={type} onChange={(nextType) => { - if ( - nextType === 'menu' && - (variant === 'surface' || variant === 'branded') - ) { + if (nextType === 'menu' && variant === 'branded') { setVariant('primaryContainer'); } setType(nextType); @@ -234,10 +228,7 @@ const FABExample = () => { alignment={position} trigger={{ icon: 'pencil', - variant: - activeVariant === 'surface' || activeVariant === 'branded' - ? undefined - : activeVariant, + variant: activeVariant === 'branded' ? undefined : activeVariant, containerColor: activeContainerColor, size, visible: showFab, diff --git a/src/components/FAB/Extended.tsx b/src/components/FAB/Extended.tsx index a5e4f28f3c..15c9a0ad1e 100644 --- a/src/components/FAB/Extended.tsx +++ b/src/components/FAB/Extended.tsx @@ -40,11 +40,6 @@ export type Props = { label: string; /** * Role-color preset. Defaults to `primaryContainer`. - * Choose `primary`, `primaryContainer`, `secondary`, `secondaryContainer`, - * `tertiary`, `tertiaryContainer`, `surface`, or `branded`. - * `surface` and `branded` use `surfaceContainerHigh`; `surface` uses primary - * content, while `branded` uses on-surface content. Pass a custom icon source - * to preserve brand artwork colors. */ variant?: Variant; /** diff --git a/src/components/FAB/FAB.tsx b/src/components/FAB/FAB.tsx index 5a02589adf..961dfdd16b 100644 --- a/src/components/FAB/FAB.tsx +++ b/src/components/FAB/FAB.tsx @@ -22,11 +22,6 @@ export type Props = { icon: IconSource; /** * Role-color preset. Defaults to `primaryContainer`. - * Choose `primary`, `primaryContainer`, `secondary`, `secondaryContainer`, - * `tertiary`, `tertiaryContainer`, `surface`, or `branded`. - * `surface` and `branded` use `surfaceContainerHigh`; `surface` uses primary - * content, while `branded` uses on-surface content. Pass a custom icon source - * to preserve brand artwork colors. */ variant?: Variant; /** diff --git a/src/components/FAB/Menu.tsx b/src/components/FAB/Menu.tsx index 476e28aa8b..fce5529647 100644 --- a/src/components/FAB/Menu.tsx +++ b/src/components/FAB/Menu.tsx @@ -50,7 +50,7 @@ export type MenuItemProps = { testID?: string; }; -type MenuVariant = Exclude; +type MenuVariant = Exclude; export type MenuTriggerProps = { /** @@ -461,7 +461,6 @@ const MorphingTrigger = ({ ]} > (null); + const previousFocusedElement = React.useRef(null); const hasHandler = hasTouchHandler({ onPress, onLongPress, onPressOut }); - // Explicit elevations (including flat menu items) keep their own treatment. const resolvedElevation = - elevation ?? - (Platform.OS === 'web' && visible && hasHandler + visible && hasHandler ? pressed ? Tokens.stateElevation.pressed - : focused - ? Tokens.stateElevation.focus - : hovered - ? Tokens.stateElevation.hover - : Tokens.stateElevation.enabled - : Tokens.stateElevation.enabled); + : hovered + ? Tokens.stateElevation.hover + : Tokens.stateElevation.enabled + : Tokens.stateElevation.enabled; const dimensions = React.useMemo( () => getDimensions({ theme, size, shape, iconSize, leading, trailing }), @@ -351,15 +341,31 @@ const Shell = ({ ); React.useEffect(() => { - if (!visible || !hasHandler) { - if (Platform.OS === 'web') { - touchableRef.current?.blur(); + if (!visible) { + if (Platform.OS === 'web' && typeof document !== 'undefined') { + const target: unknown = touchableRef.current; + if ( + target instanceof HTMLElement && + target === document.activeElement + ) { + if (previousFocusedElement.current?.isConnected) { + previousFocusedElement.current.focus({ preventScroll: true }); + } + // The previous element may have been removed or become unfocusable. + if (target === document.activeElement) target.blur(); + } } setHovered(false); setPressed(false); - setFocused(false); } - }, [visible, hasHandler]); + }, [visible]); + + React.useEffect(() => { + if (!hasHandler) { + setHovered(false); + setPressed(false); + } + }, [hasHandler]); // Without a handler the touchable drops the button role, and on web that // renders role="presentation", which can't carry a name. A labelled @@ -401,7 +407,10 @@ const Shell = ({ onPress={visible ? onPress : undefined} onLongPress={visible ? onLongPress : undefined} delayLongPress={delayLongPress} - disabled={disabled || !hasHandler || !visible} + disabled={disabled || !hasHandler} + accessible={visible} + focusable={visible && hasHandler} + tabIndex={visible ? undefined : -1} onHoverIn={() => setHovered(true)} onHoverOut={() => setHovered(false)} onPressIn={() => setPressed(true)} @@ -410,13 +419,17 @@ const Shell = ({ onPressOut?.(event); }} onFocus={(event) => { - setFocused(true); + if (Platform.OS === 'web') { + const previous = + 'relatedTarget' in event.nativeEvent + ? event.nativeEvent.relatedTarget + : null; + previousFocusedElement.current = + previous instanceof HTMLElement ? previous : null; + } focusTarget.onFocus?.(event); }} - onBlur={() => { - setFocused(false); - focusTarget.onBlur?.(); - }} + onBlur={focusTarget.onBlur} aria-label={ariaLabel} role={isWebImage ? 'img' : 'button'} aria-checked={ariaChecked} diff --git a/src/components/FAB/tokens.ts b/src/components/FAB/tokens.ts index bf7a8d95e7..47b1a954d1 100644 --- a/src/components/FAB/tokens.ts +++ b/src/components/FAB/tokens.ts @@ -12,7 +12,6 @@ export type Variant = | 'primaryContainer' | 'secondaryContainer' | 'tertiaryContainer' - | 'surface' | 'branded'; export type Size = 'default' | 'medium' | 'large'; @@ -67,7 +66,7 @@ const stateElevation = { } as const satisfies Record; const variants = { - surface: { container: 'surfaceContainerHigh', content: 'primary' }, + // Branded artwork has no prescribed icon color; onSurface is a fallback. branded: { container: 'surfaceContainerHigh', content: 'onSurface' }, primary: { container: 'primary', content: 'onPrimary' }, secondary: { container: 'secondary', content: 'onSecondary' }, diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 6d82b7b46c..b6e8b0e8ca 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -1,4 +1,5 @@ -import { Platform } from 'react-native'; +import * as React from 'react'; +import { Platform, View } from 'react-native'; import { afterEach, @@ -11,15 +12,16 @@ import { import { fireEvent, userEvent } from '@testing-library/react-native'; import * as Reanimated from 'react-native-reanimated'; +import { getAnimatedStyle } from 'react-native-reanimated'; + import PaperProvider from '../../core/PaperProvider'; -import { getTheme } from '../../core/theming'; import { render, screen } from '../../test-utils'; +import { LightTheme } from '../../theme/schemes'; import { androidElevationLevels, shadow, } from '../../theme/tokens/sys/elevation'; import FAB from '../FAB'; -import Shell from '../FAB/Shell'; import Tooltip from '../Tooltip/Tooltip'; jest.mock('react-native-reanimated', () => { @@ -284,129 +286,177 @@ describe('without a touch handler', () => { }); }); +const getStyle = (ref: React.RefObject) => { + if (!ref.current) throw new Error('Expected FAB ref to be attached'); + return getAnimatedStyle(ref.current); +}; + it.each(['icon', 'extended'] as const)( 'applies web hover elevation to the %s FAB and restores it after press and exit', async (type) => { jest.replaceProperty(Platform, 'OS', 'web'); + const ref = React.createRef(); const onPress = jest.fn(); await render( type === 'icon' ? ( - + ) : ( ) ); - const fab = screen.getByTestId('floating-action-button'); - const container = screen.getByTestId('floating-action-button-container'); - const theme = getTheme(); - const [restingShadow] = shadow(3, theme.colors.shadow); - const [hoverShadow] = shadow(4, theme.colors.shadow); + const fab = screen.getByRole('button', { name: 'Create' }); + const [restingShadow] = shadow(3, LightTheme.colors.shadow); + const [hoverShadow] = shadow(4, LightTheme.colors.shadow); - expect(container).toHaveStyle(restingShadow); + expect(getStyle(ref)).toMatchObject(restingShadow); await fireEvent(fab, 'hoverIn'); - expect(container).toHaveStyle(hoverShadow); + expect(getStyle(ref)).toMatchObject(hoverShadow); await fireEvent(fab, 'pressIn'); - expect(container).toHaveStyle(restingShadow); + expect(getStyle(ref)).toMatchObject(restingShadow); await fireEvent(fab, 'pressOut'); - expect(container).toHaveStyle(hoverShadow); + expect(getStyle(ref)).toMatchObject(hoverShadow); await fireEvent(fab, 'hoverOut'); - expect(container).toHaveStyle(restingShadow); + expect(getStyle(ref)).toMatchObject(restingShadow); } ); -it('keeps an explicit shell elevation of zero on hover', async () => { - jest.replaceProperty(Platform, 'OS', 'web'); - await render( {}} elevation={0} />); - await fireEvent(screen.getByTestId('fab-shell'), 'hoverIn'); - const [flatShadow] = shadow(0, getTheme().colors.shadow); - expect(screen.getByTestId('fab-shell-container')).toHaveStyle(flatShadow); -}); - it('does not enable a FAB without an action when adding interaction handlers', async () => { await render(); expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); }); -it('hides an invisible FAB from accessibility and disables its action', async () => { +it('hides an invisible FAB from accessibility and keyboard navigation without marking it disabled', async () => { const onPress = jest.fn(); await render( - + ); expect(screen.queryByRole('button', { name: 'Create' })).toBeNull(); - const fab = screen.getByTestId('floating-action-button', { - includeHiddenElements: true, - }); - expect(fab).toBeDisabled(); + const fab = screen.getByTestId('create', { includeHiddenElements: true }); + expect(fab).not.toBeDisabled(); + expect(fab).toHaveProp('accessible', false); + expect(fab).toHaveProp('focusable', false); + expect(fab).toHaveProp('tabIndex', -1); await userEvent.press(fab); expect(onPress).not.toHaveBeenCalled(); }); it('clears interaction elevation when a FAB is hidden and shown again', async () => { - jest.replaceProperty(Platform, 'OS', 'web'); + const ref = React.createRef(); const onPress = jest.fn(); - const { rerender } = await render(); - await fireEvent(screen.getByTestId('floating-action-button'), 'hoverIn'); - await rerender(); - await rerender(); - const [restingShadow] = shadow(3, getTheme().colors.shadow); - expect(screen.getByTestId('floating-action-button-container')).toHaveStyle( - restingShadow + const { rerender } = await render( + + ); + await fireEvent(screen.getByRole('button', { name: 'Create' }), 'hoverIn'); + await rerender( + ); + await rerender(); + const [restingShadow] = shadow(3, LightTheme.colors.shadow); + expect(getStyle(ref)).toMatchObject(restingShadow); }); -it('keeps the menu trigger at its existing elevation on web', async () => { - jest.replaceProperty(Platform, 'OS', 'web'); - await render( +it('uses the shared FAB hover elevation for the menu trigger', async () => { + const { toJSON } = await render( {}} - trigger={{ icon: 'plus', testID: 'menu-trigger', onPress: () => {} }} + trigger={{ icon: 'plus', 'aria-label': 'Create', onPress: () => {} }} items={[ { label: 'First', onPress: () => {} }, { label: 'Second', onPress: () => {} }, ]} /> ); - await fireEvent(screen.getByTestId('fab-shell'), 'hoverIn'); - const [restingShadow] = shadow(3, getTheme().colors.shadow); - expect(screen.getByTestId('fab-shell-container')).toHaveStyle(restingShadow); + const before = JSON.stringify(toJSON()); + await fireEvent(screen.getByRole('button', { name: 'Create' }), 'hoverIn'); + const hovered = JSON.stringify(toJSON()); + expect(hovered).not.toBe(before); + await fireEvent(screen.getByRole('button', { name: 'Create' }), 'hoverOut'); + expect(JSON.stringify(toJSON())).toBe(before); }); it.each(['ios', 'android'] as const)( - 'keeps native elevation unchanged on hover on %s', + 'applies hover elevation alongside focus and restores it after press on %s', async (platform) => { jest.replaceProperty(Platform, 'OS', platform); - await render( {}} />); - await fireEvent(screen.getByTestId('floating-action-button'), 'hoverIn'); - const [restingShadow] = shadow(3, getTheme().colors.shadow); - expect(screen.getByTestId('floating-action-button-container')).toHaveStyle( + const ref = React.createRef(); + await render( + {}} + /> + ); + const fab = screen.getByRole('button', { name: 'Create' }); + const [restingShadow] = shadow(3, LightTheme.colors.shadow); + const [hoverShadow] = shadow(4, LightTheme.colors.shadow); + const restingStyle = platform === 'android' ? { elevation: androidElevationLevels[3] } - : restingShadow - ); + : restingShadow; + const hoverStyle = + platform === 'android' + ? { elevation: androidElevationLevels[4] } + : hoverShadow; + + await fireEvent(fab, 'focus', { nativeEvent: {} }); + expect(getStyle(ref)).toMatchObject(restingStyle); + await fireEvent(fab, 'hoverIn'); + expect(getStyle(ref)).toMatchObject(hoverStyle); + await fireEvent(fab, 'focus', { nativeEvent: {} }); + expect(getStyle(ref)).toMatchObject(hoverStyle); + await fireEvent(fab, 'pressIn'); + expect(getStyle(ref)).toMatchObject(restingStyle); + await fireEvent(fab, 'pressOut'); + expect(getStyle(ref)).toMatchObject(hoverStyle); + await fireEvent(fab, 'hoverOut'); + expect(getStyle(ref)).toMatchObject(restingStyle); } ); -it('restores the resting elevation when a hovered FAB is hidden or its action is removed', async () => { - jest.replaceProperty(Platform, 'OS', 'web'); - const onPress = jest.fn(); - const { rerender } = await render(); - await fireEvent(screen.getByTestId('floating-action-button'), 'hoverIn'); - await rerender(); - const [restingShadow] = shadow(3, getTheme().colors.shadow); - expect( - screen.getByTestId('floating-action-button-container', { - includeHiddenElements: true, - }) - ).toHaveStyle(restingShadow); - await rerender(); - expect(screen.getByTestId('floating-action-button-container')).toHaveStyle( - restingShadow +it('restores the resting elevation when a hovered FAB loses its action', async () => { + const ref = React.createRef(); + const { rerender } = await render( + {}} + /> ); + await fireEvent(screen.getByRole('button', { name: 'Create' }), 'hoverIn'); + await rerender(); + const [restingShadow] = shadow(3, LightTheme.colors.shadow); + expect(getStyle(ref)).toMatchObject(restingShadow); + expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); + await rerender( {}} />); + expect(getStyle(ref)).toMatchObject(restingShadow); }); diff --git a/src/components/__tests__/FABUtils.test.tsx b/src/components/__tests__/FABUtils.test.tsx index 75a0068ed5..6d80f0bc4e 100644 --- a/src/components/__tests__/FABUtils.test.tsx +++ b/src/components/__tests__/FABUtils.test.tsx @@ -5,7 +5,7 @@ import { getDimensions, resolveColors } from '../FAB/utils'; describe('resolveColors', () => { it.each([false, true])( - 'resolves every MD3 color variant (dark=%s)', + 'resolves every FAB color preset (dark=%s)', (dark) => { const theme = dark ? DarkTheme : LightTheme; const variants = { @@ -15,7 +15,6 @@ describe('resolveColors', () => { secondaryContainer: ['secondaryContainer', 'onSecondaryContainer'], tertiary: ['tertiary', 'onTertiary'], tertiaryContainer: ['tertiaryContainer', 'onTertiaryContainer'], - surface: ['surfaceContainerHigh', 'primary'], branded: ['surfaceContainerHigh', 'onSurface'], } as const; @@ -26,7 +25,6 @@ describe('resolveColors', () => { 'secondaryContainer', 'tertiary', 'tertiaryContainer', - 'surface', 'branded', ] as const; for (const variant of variantNames) { diff --git a/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap b/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap index 1682b937dd..8d51ca484b 100644 --- a/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/FABMenu.test.tsx.snap @@ -554,7 +554,7 @@ exports[`renders FAB.Menu closed 1`] = ` } accessible={true} collapsable={false} - focusable={true} + focusable={false} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -1258,9 +1258,9 @@ exports[`renders FAB.Menu not expanded when trigger is not visible 1`] = ` "text": undefined, } } - accessible={true} + accessible={false} collapsable={false} - focusable={true} + focusable={false} onBlur={[Function]} onClick={[Function]} onFocus={[Function]} @@ -1283,6 +1283,7 @@ exports[`renders FAB.Menu not expanded when trigger is not visible 1`] = ` ], ] } + tabIndex={-1} > Date: Wed, 23 Sep 2026 11:28:58 +0200 Subject: [PATCH 03/25] fix(fab): skip hidden focus restoration targets --- src/components/FAB/Shell.tsx | 8 ++++++-- src/components/__tests__/FAB.test.tsx | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/FAB/Shell.tsx b/src/components/FAB/Shell.tsx index e938a4a52d..ab1ebee11f 100644 --- a/src/components/FAB/Shell.tsx +++ b/src/components/FAB/Shell.tsx @@ -348,8 +348,12 @@ const Shell = ({ target instanceof HTMLElement && target === document.activeElement ) { - if (previousFocusedElement.current?.isConnected) { - previousFocusedElement.current.focus({ preventScroll: true }); + const previous = previousFocusedElement.current; + if ( + previous?.isConnected && + !previous.closest('[aria-hidden="true"], [inert]') + ) { + previous.focus({ preventScroll: true }); } // The previous element may have been removed or become unfocusable. if (target === document.activeElement) target.blur(); diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index b6e8b0e8ca..153f193560 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -11,7 +11,6 @@ import { } from '@jest/globals'; import { fireEvent, userEvent } from '@testing-library/react-native'; import * as Reanimated from 'react-native-reanimated'; - import { getAnimatedStyle } from 'react-native-reanimated'; import PaperProvider from '../../core/PaperProvider'; From afdb35fde64aedba6632154c86a4b1905eb40432 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 12:59:23 +0100 Subject: [PATCH 04/25] fix(fab): remove the branded variant The branded FAB comes from material-web's md-branded-fab, which is meant for multicolor brand logos and has no icon color token, so it is not one of the MD3 FAB color styles. Removing it also removes the menu-only variant type and the example's special cases for it. --- example/src/Examples/FABExample.tsx | 19 +++---------------- src/components/FAB/Menu.tsx | 12 +++++------- src/components/FAB/tokens.ts | 5 +---- src/components/__tests__/FABUtils.test.tsx | 2 -- 4 files changed, 9 insertions(+), 29 deletions(-) diff --git a/example/src/Examples/FABExample.tsx b/example/src/Examples/FABExample.tsx index f878c61b24..afa758fca9 100644 --- a/example/src/Examples/FABExample.tsx +++ b/example/src/Examples/FABExample.tsx @@ -37,7 +37,6 @@ const variants: FabColor[] = [ 'primaryContainer', 'secondaryContainer', 'tertiaryContainer', - 'branded', 'custom', ]; @@ -139,24 +138,12 @@ const FABExample = () => { v !== 'branded') : variants - } + options={variants} value={variant} onChange={setVariant} /> - { - if (nextType === 'menu' && variant === 'branded') { - setVariant('primaryContainer'); - } - setType(nextType); - }} - /> + { alignment={position} trigger={{ icon: 'pencil', - variant: activeVariant === 'branded' ? undefined : activeVariant, + variant: activeVariant, containerColor: activeContainerColor, size, visible: showFab, diff --git a/src/components/FAB/Menu.tsx b/src/components/FAB/Menu.tsx index fce5529647..2aa808bb5e 100644 --- a/src/components/FAB/Menu.tsx +++ b/src/components/FAB/Menu.tsx @@ -50,15 +50,13 @@ export type MenuItemProps = { testID?: string; }; -type MenuVariant = Exclude; - export type MenuTriggerProps = { /** * Icon displayed in the trigger FAB (and cross-faded to `closeIcon` when * the menu is open). */ icon: IconSource; - variant?: MenuVariant; + variant?: Variant; size?: Size; containerColor?: ColorValue; contentColor?: ColorValue; @@ -118,7 +116,7 @@ export type MenuProps = { * The close button is always the saturated role color; items are always the * tonal (container) role color. */ -const getCloseVariant = (triggerVariant: MenuVariant): Variant => { +const getCloseVariant = (triggerVariant: Variant): Variant => { if (triggerVariant === 'primary' || triggerVariant === 'primaryContainer') { return 'primary'; } @@ -131,7 +129,7 @@ const getCloseVariant = (triggerVariant: MenuVariant): Variant => { return 'tertiary'; }; -const getItemsVariant = (triggerVariant: MenuVariant): Variant => { +const getItemsVariant = (triggerVariant: Variant): Variant => { if (triggerVariant === 'primary' || triggerVariant === 'primaryContainer') { return 'primaryContainer'; } @@ -314,7 +312,7 @@ const MenuItem = ({ }; type MorphingTriggerProps = { - triggerVariant: MenuVariant; + triggerVariant: Variant; closeVariant: Variant; triggerContainerColor?: ColorValue; triggerContentColor?: ColorValue; @@ -559,7 +557,7 @@ const Menu = ({ const isRTL = direction === 'rtl'; const insets = useSafeAreaInsets(); - const triggerVariant: MenuVariant = trigger.variant ?? 'primaryContainer'; + const triggerVariant: Variant = trigger.variant ?? 'primaryContainer'; const size: Size = trigger.size ?? 'default'; const openIcon: IconSource = trigger.icon; const openOnPress = trigger.onPress; diff --git a/src/components/FAB/tokens.ts b/src/components/FAB/tokens.ts index 47b1a954d1..b83c18edf0 100644 --- a/src/components/FAB/tokens.ts +++ b/src/components/FAB/tokens.ts @@ -11,8 +11,7 @@ export type Variant = | 'tertiary' | 'primaryContainer' | 'secondaryContainer' - | 'tertiaryContainer' - | 'branded'; + | 'tertiaryContainer'; export type Size = 'default' | 'medium' | 'large'; @@ -66,8 +65,6 @@ const stateElevation = { } as const satisfies Record; const variants = { - // Branded artwork has no prescribed icon color; onSurface is a fallback. - branded: { container: 'surfaceContainerHigh', content: 'onSurface' }, primary: { container: 'primary', content: 'onPrimary' }, secondary: { container: 'secondary', content: 'onSecondary' }, tertiary: { container: 'tertiary', content: 'onTertiary' }, diff --git a/src/components/__tests__/FABUtils.test.tsx b/src/components/__tests__/FABUtils.test.tsx index 6d80f0bc4e..d5bb8b87f0 100644 --- a/src/components/__tests__/FABUtils.test.tsx +++ b/src/components/__tests__/FABUtils.test.tsx @@ -15,7 +15,6 @@ describe('resolveColors', () => { secondaryContainer: ['secondaryContainer', 'onSecondaryContainer'], tertiary: ['tertiary', 'onTertiary'], tertiaryContainer: ['tertiaryContainer', 'onTertiaryContainer'], - branded: ['surfaceContainerHigh', 'onSurface'], } as const; const variantNames = [ @@ -25,7 +24,6 @@ describe('resolveColors', () => { 'secondaryContainer', 'tertiary', 'tertiaryContainer', - 'branded', ] as const; for (const variant of variantNames) { const [container, content] = variants[variant]; From 707adba5a9612e412e78ba31b67a00770978eb12 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 13:00:47 +0100 Subject: [PATCH 05/25] refactor(fab): drop the redundant document check Effects do not run during server rendering and document always exists on web, so the check never fails. --- src/components/FAB/Shell.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/FAB/Shell.tsx b/src/components/FAB/Shell.tsx index ab1ebee11f..ad016f72c8 100644 --- a/src/components/FAB/Shell.tsx +++ b/src/components/FAB/Shell.tsx @@ -342,7 +342,7 @@ const Shell = ({ React.useEffect(() => { if (!visible) { - if (Platform.OS === 'web' && typeof document !== 'undefined') { + if (Platform.OS === 'web') { const target: unknown = touchableRef.current; if ( target instanceof HTMLElement && From a09b6fb8a811b07cd2c32b33085e959c0fd32bf4 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 13:01:00 +0100 Subject: [PATCH 06/25] fix(fab): name the menu trigger in the example The menu trigger is an icon-only FAB, so without a label it is announced as an unnamed button. --- example/src/Examples/FABExample.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/example/src/Examples/FABExample.tsx b/example/src/Examples/FABExample.tsx index afa758fca9..e6470cc091 100644 --- a/example/src/Examples/FABExample.tsx +++ b/example/src/Examples/FABExample.tsx @@ -215,6 +215,7 @@ const FABExample = () => { alignment={position} trigger={{ icon: 'pencil', + 'aria-label': 'Compose', variant: activeVariant, containerColor: activeContainerColor, size, From cbcf406f9c3ce5f39fccc39a442e381e044a256a Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 14:11:17 +0100 Subject: [PATCH 07/25] fix(fab): restore focus only after keyboard focus Browsers also focus the FAB on a mouse click or tap, so moving focus back to the previous element when it hides could jump into an earlier text field. Check :focus-visible at hide time and blur in the other cases. --- src/components/FAB/Shell.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/FAB/Shell.tsx b/src/components/FAB/Shell.tsx index ad016f72c8..491f46ed0f 100644 --- a/src/components/FAB/Shell.tsx +++ b/src/components/FAB/Shell.tsx @@ -349,13 +349,17 @@ const Shell = ({ target === document.activeElement ) { const previous = previousFocusedElement.current; + // Only restore keyboard focus. A mouse click or tap also focuses the + // FAB, and moving focus back could jump into an earlier text field. if ( + target.matches(':focus-visible') && previous?.isConnected && !previous.closest('[aria-hidden="true"], [inert]') ) { previous.focus({ preventScroll: true }); } - // The previous element may have been removed or become unfocusable. + // Blur when focus didn't move back, e.g. after a mouse click or when + // the previous element is gone or can't take focus. if (target === document.activeElement) target.blur(); } } From f4c1fe6f76d7fcdff30e4e769193eacd584941a5 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 14:11:56 +0100 Subject: [PATCH 08/25] test(fab): name the disabled FAB test after its behavior --- src/components/__tests__/FAB.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 153f193560..9791682642 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -332,7 +332,7 @@ it.each(['icon', 'extended'] as const)( } ); -it('does not enable a FAB without an action when adding interaction handlers', async () => { +it('renders a FAB without onPress as a disabled button', async () => { await render(); expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); }); From eb1fca07cf3c13a9c59bfc8cd979577b0be7fdf3 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 14:12:00 +0100 Subject: [PATCH 09/25] test(fab): cover the press guard on a hidden FAB userEvent.press is already blocked by pointerEvents none, so the test passed without the guard. A click event still reaches the pressable and fails the test when the guard is removed. --- src/components/__tests__/FAB.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 9791682642..4e230fc91d 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -355,6 +355,7 @@ it('hides an invisible FAB from accessibility and keyboard navigation without ma expect(fab).toHaveProp('focusable', false); expect(fab).toHaveProp('tabIndex', -1); await userEvent.press(fab); + await fireEvent(fab, 'click', { nativeEvent: {} }); expect(onPress).not.toHaveBeenCalled(); }); From d553d570d83bf4af3a574759943e1d4c9b8c698b Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 14:12:04 +0100 Subject: [PATCH 10/25] test(fab): cover focus restoration when a FAB hides on web Cover moving focus back after keyboard focus, blurring instead when the previous element is hidden, inert or disconnected or when the FAB was focused by a mouse click, and leaving focus alone when the FAB no longer has it. --- src/components/__tests__/FAB.test.tsx | 160 ++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 4e230fc91d..85e676b9cb 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -460,3 +460,163 @@ it('restores the resting elevation when a hovered FAB loses its action', async ( await rerender( {}} />); expect(getStyle(ref)).toMatchObject(restingShadow); }); + +describe('on web', () => { + const originalHTMLElement = Object.getOwnPropertyDescriptor( + globalThis, + 'HTMLElement' + ); + const originalDocument = Object.getOwnPropertyDescriptor( + globalThis, + 'document' + ); + const originalMatches = Object.getOwnPropertyDescriptor( + View.prototype, + 'matches' + ); + const originalComponentDidMount = Object.getOwnPropertyDescriptor( + View.prototype, + 'componentDidMount' + ); + let activeElement: unknown; + let focusVisible: boolean; + let fabElement: View | undefined; + + beforeEach(() => { + jest.replaceProperty(Platform, 'OS', 'web'); + activeElement = null; + focusVisible = true; + fabElement = undefined; + // Native View refs stand in for DOM elements in the native test renderer. + Object.defineProperty(globalThis, 'HTMLElement', { + configurable: true, + value: View, + }); + Object.defineProperty(globalThis, 'document', { + configurable: true, + value: { + get activeElement() { + return activeElement; + }, + }, + }); + Object.defineProperty(View.prototype, 'matches', { + configurable: true, + value: (selectors: string) => + selectors === ':focus-visible' && focusVisible, + }); + // The pressable view with the FAB's testID is the element that takes focus. + Object.defineProperty(View.prototype, 'componentDidMount', { + configurable: true, + value(this: View) { + if (this.props.testID === 'create') { + fabElement = this; + } + }, + }); + }); + + afterEach(() => { + for (const [target, key, descriptor] of [ + [globalThis, 'HTMLElement', originalHTMLElement], + [globalThis, 'document', originalDocument], + [View.prototype, 'matches', originalMatches], + [View.prototype, 'componentDidMount', originalComponentDidMount], + ] as const) { + if (descriptor) { + Object.defineProperty(target, key, descriptor); + } else { + Reflect.deleteProperty(target, key); + } + } + }); + + const createElement = ({ + isConnected = true, + hiddenBy, + }: { + isConnected?: boolean; + hiddenBy?: string; + } = {}) => { + const element = new View({}); + return Object.assign(element, { + isConnected, + closest: (selectors: string) => + hiddenBy && selectors.includes(hiddenBy) ? {} : null, + focus: jest.fn(() => { + activeElement = element; + }), + }); + }; + + const renderFocusedFAB = async (relatedTarget: unknown) => { + const fab = (visible: boolean) => ( + {}} + visible={visible} + /> + ); + const { rerender } = await render(fab(true)); + if (!fabElement) throw new Error('Expected the FAB to mount'); + activeElement = fabElement; + // The View mock shares one `blur` mock across instances. + const blur = jest.fn(); + fabElement.blur = blur; + await fireEvent(screen.getByRole('button', { name: 'Create' }), 'focus', { + nativeEvent: { relatedTarget }, + }); + return { blur, hide: () => rerender(fab(false)) }; + }; + + it('moves focus back to the previous element when a keyboard-focused FAB hides', async () => { + const previous = createElement(); + const { blur, hide } = await renderFocusedFAB(previous); + + await hide(); + + expect(previous.focus).toHaveBeenCalledWith({ preventScroll: true }); + expect(blur).not.toHaveBeenCalled(); + }); + + it.each([ + ['inside an aria-hidden subtree', { hiddenBy: '[aria-hidden="true"]' }], + ['inside an inert subtree', { hiddenBy: '[inert]' }], + ['disconnected', { isConnected: false }], + ])( + 'blurs a keyboard-focused FAB that hides when the previous element is %s', + async (_, options) => { + const previous = createElement(options); + const { blur, hide } = await renderFocusedFAB(previous); + + await hide(); + + expect(previous.focus).not.toHaveBeenCalled(); + expect(blur).toHaveBeenCalledTimes(1); + } + ); + + it('blurs a FAB focused by a mouse click instead of moving focus back', async () => { + focusVisible = false; + const previous = createElement(); + const { blur, hide } = await renderFocusedFAB(previous); + + await hide(); + + expect(previous.focus).not.toHaveBeenCalled(); + expect(blur).toHaveBeenCalledTimes(1); + }); + + it('leaves focus alone when a FAB that lost focus hides', async () => { + const previous = createElement(); + const { blur, hide } = await renderFocusedFAB(previous); + activeElement = createElement(); + + await hide(); + + expect(previous.focus).not.toHaveBeenCalled(); + expect(blur).not.toHaveBeenCalled(); + }); +}); From a80ae79f21875b202039291f399d4c80cbd20824 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 14:12:09 +0100 Subject: [PATCH 11/25] test(fab): compare elevation between interaction states Compare the FAB's own style between hover, focus and press states instead of asserting the Surface shadow tokens, and describe the iOS and Android cases by what they check, since React Native 0.85 sends no hover events there by default. --- src/components/__tests__/FAB.test.tsx | 128 ++++++++++++-------------- 1 file changed, 58 insertions(+), 70 deletions(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 85e676b9cb..d3a6f31130 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -15,11 +15,6 @@ import { getAnimatedStyle } from 'react-native-reanimated'; import PaperProvider from '../../core/PaperProvider'; import { render, screen } from '../../test-utils'; -import { LightTheme } from '../../theme/schemes'; -import { - androidElevationLevels, - shadow, -} from '../../theme/tokens/sys/elevation'; import FAB from '../FAB'; import Tooltip from '../Tooltip/Tooltip'; @@ -290,48 +285,6 @@ const getStyle = (ref: React.RefObject) => { return getAnimatedStyle(ref.current); }; -it.each(['icon', 'extended'] as const)( - 'applies web hover elevation to the %s FAB and restores it after press and exit', - async (type) => { - jest.replaceProperty(Platform, 'OS', 'web'); - const ref = React.createRef(); - const onPress = jest.fn(); - await render( - type === 'icon' ? ( - - ) : ( - - ) - ); - const fab = screen.getByRole('button', { name: 'Create' }); - const [restingShadow] = shadow(3, LightTheme.colors.shadow); - const [hoverShadow] = shadow(4, LightTheme.colors.shadow); - - expect(getStyle(ref)).toMatchObject(restingShadow); - await fireEvent(fab, 'hoverIn'); - expect(getStyle(ref)).toMatchObject(hoverShadow); - await fireEvent(fab, 'pressIn'); - expect(getStyle(ref)).toMatchObject(restingShadow); - await fireEvent(fab, 'pressOut'); - expect(getStyle(ref)).toMatchObject(hoverShadow); - await fireEvent(fab, 'hoverOut'); - expect(getStyle(ref)).toMatchObject(restingShadow); - } -); - it('renders a FAB without onPress as a disabled button', async () => { await render(); expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); @@ -371,13 +324,14 @@ it('clears interaction elevation when a FAB is hidden and shown again', async () onPress={onPress} /> ); + const resting = getStyle(ref); await fireEvent(screen.getByRole('button', { name: 'Create' }), 'hoverIn'); + expect(getStyle(ref)).not.toEqual(resting); await rerender( ); await rerender(); - const [restingShadow] = shadow(3, LightTheme.colors.shadow); - expect(getStyle(ref)).toMatchObject(restingShadow); + expect(getStyle(ref)).toEqual(resting); }); it('uses the shared FAB hover elevation for the menu trigger', async () => { @@ -400,8 +354,10 @@ it('uses the shared FAB hover elevation for the menu trigger', async () => { expect(JSON.stringify(toJSON())).toBe(before); }); +// React Native 0.85 sends no hover events on iOS or Android by default. These +// only check that the elevation logic itself has no platform check. it.each(['ios', 'android'] as const)( - 'applies hover elevation alongside focus and restores it after press on %s', + 'follows hover events and keeps the hover elevation on focus when Platform.OS is %s', async (platform) => { jest.replaceProperty(Platform, 'OS', platform); const ref = React.createRef(); @@ -415,29 +371,19 @@ it.each(['ios', 'android'] as const)( /> ); const fab = screen.getByRole('button', { name: 'Create' }); - const [restingShadow] = shadow(3, LightTheme.colors.shadow); - const [hoverShadow] = shadow(4, LightTheme.colors.shadow); - const restingStyle = - platform === 'android' - ? { elevation: androidElevationLevels[3] } - : restingShadow; - const hoverStyle = - platform === 'android' - ? { elevation: androidElevationLevels[4] } - : hoverShadow; + const resting = getStyle(ref); - await fireEvent(fab, 'focus', { nativeEvent: {} }); - expect(getStyle(ref)).toMatchObject(restingStyle); await fireEvent(fab, 'hoverIn'); - expect(getStyle(ref)).toMatchObject(hoverStyle); + const hovered = getStyle(ref); + expect(hovered).not.toEqual(resting); await fireEvent(fab, 'focus', { nativeEvent: {} }); - expect(getStyle(ref)).toMatchObject(hoverStyle); + expect(getStyle(ref)).toEqual(hovered); await fireEvent(fab, 'pressIn'); - expect(getStyle(ref)).toMatchObject(restingStyle); + expect(getStyle(ref)).toEqual(resting); await fireEvent(fab, 'pressOut'); - expect(getStyle(ref)).toMatchObject(hoverStyle); + expect(getStyle(ref)).toEqual(hovered); await fireEvent(fab, 'hoverOut'); - expect(getStyle(ref)).toMatchObject(restingStyle); + expect(getStyle(ref)).toEqual(resting); } ); @@ -452,13 +398,14 @@ it('restores the resting elevation when a hovered FAB loses its action', async ( onPress={() => {}} /> ); + const resting = getStyle(ref); await fireEvent(screen.getByRole('button', { name: 'Create' }), 'hoverIn'); + expect(getStyle(ref)).not.toEqual(resting); await rerender(); - const [restingShadow] = shadow(3, LightTheme.colors.shadow); - expect(getStyle(ref)).toMatchObject(restingShadow); + expect(getStyle(ref)).toEqual(resting); expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); await rerender( {}} />); - expect(getStyle(ref)).toMatchObject(restingShadow); + expect(getStyle(ref)).toEqual(resting); }); describe('on web', () => { @@ -571,6 +518,47 @@ describe('on web', () => { return { blur, hide: () => rerender(fab(false)) }; }; + it.each(['icon', 'extended'] as const)( + 'raises the %s FAB while hovered, keeps it raised on focus and lowers it while pressed', + async (type) => { + const ref = React.createRef(); + await render( + type === 'icon' ? ( + {}} + /> + ) : ( + {}} + /> + ) + ); + const fab = screen.getByRole('button', { name: 'Create' }); + const resting = getStyle(ref); + + await fireEvent(fab, 'hoverIn'); + const hovered = getStyle(ref); + expect(hovered).not.toEqual(resting); + await fireEvent(fab, 'focus', { nativeEvent: {} }); + expect(getStyle(ref)).toEqual(hovered); + await fireEvent(fab, 'pressIn'); + expect(getStyle(ref)).toEqual(resting); + await fireEvent(fab, 'pressOut'); + expect(getStyle(ref)).toEqual(hovered); + await fireEvent(fab, 'hoverOut'); + expect(getStyle(ref)).toEqual(resting); + } + ); + it('moves focus back to the previous element when a keyboard-focused FAB hides', async () => { const previous = createElement(); const { blur, hide } = await renderFocusedFAB(previous); From 967933ac1611963ec55ef80903625d096f3299ab Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 15:04:34 +0100 Subject: [PATCH 12/25] test(fab): check that focus alone keeps the resting elevation MD3 keeps a focused FAB at level 3. Without this step, folding focus into the hover state would still pass the elevation tests. --- src/components/__tests__/FAB.test.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index d3a6f31130..d701a2b666 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -357,7 +357,7 @@ it('uses the shared FAB hover elevation for the menu trigger', async () => { // React Native 0.85 sends no hover events on iOS or Android by default. These // only check that the elevation logic itself has no platform check. it.each(['ios', 'android'] as const)( - 'follows hover events and keeps the hover elevation on focus when Platform.OS is %s', + 'keeps the resting elevation on focus and follows hover and press events when Platform.OS is %s', async (platform) => { jest.replaceProperty(Platform, 'OS', platform); const ref = React.createRef(); @@ -373,6 +373,8 @@ it.each(['ios', 'android'] as const)( const fab = screen.getByRole('button', { name: 'Create' }); const resting = getStyle(ref); + await fireEvent(fab, 'focus', { nativeEvent: {} }); + expect(getStyle(ref)).toEqual(resting); await fireEvent(fab, 'hoverIn'); const hovered = getStyle(ref); expect(hovered).not.toEqual(resting); @@ -519,7 +521,7 @@ describe('on web', () => { }; it.each(['icon', 'extended'] as const)( - 'raises the %s FAB while hovered, keeps it raised on focus and lowers it while pressed', + 'keeps the %s FAB at rest on focus, raises it while hovered and lowers it while pressed', async (type) => { const ref = React.createRef(); await render( @@ -545,6 +547,8 @@ describe('on web', () => { const fab = screen.getByRole('button', { name: 'Create' }); const resting = getStyle(ref); + await fireEvent(fab, 'focus', { nativeEvent: {} }); + expect(getStyle(ref)).toEqual(resting); await fireEvent(fab, 'hoverIn'); const hovered = getStyle(ref); expect(hovered).not.toEqual(resting); From d79ff09d8545ec89fe81721eb224e4056e365ad6 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 15:05:14 +0100 Subject: [PATCH 13/25] test(fab): pin the direction of the hover elevation The state comparisons only checked that hover changes the style. Android exposes elevation as a number, so assert there that hover raises it and pressing lowers it, and title the web test by what it checks. --- src/components/__tests__/FAB.test.tsx | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index d701a2b666..2b2efdd7fe 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -285,6 +285,16 @@ const getStyle = (ref: React.RefObject) => { return getAnimatedStyle(ref.current); }; +// Android exposes elevation as a plain number, so the direction is checkable +// without the shadow tokens. +const getElevation = (ref: React.RefObject) => { + const style = getStyle(ref); + if (!('elevation' in style) || typeof style.elevation !== 'number') { + throw new Error('Expected a numeric elevation'); + } + return style.elevation; +}; + it('renders a FAB without onPress as a disabled button', async () => { await render(); expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); @@ -389,6 +399,27 @@ it.each(['ios', 'android'] as const)( } ); +it('raises the elevation while hovered and lowers it while pressed when Platform.OS is android', async () => { + jest.replaceProperty(Platform, 'OS', 'android'); + const ref = React.createRef(); + await render( + {}} + /> + ); + const fab = screen.getByRole('button', { name: 'Create' }); + const resting = getElevation(ref); + + await fireEvent(fab, 'hoverIn'); + expect(getElevation(ref)).toBeGreaterThan(resting); + await fireEvent(fab, 'pressIn'); + expect(getElevation(ref)).toBe(resting); +}); + it('restores the resting elevation when a hovered FAB loses its action', async () => { const ref = React.createRef(); const { rerender } = await render( @@ -521,7 +552,7 @@ describe('on web', () => { }; it.each(['icon', 'extended'] as const)( - 'keeps the %s FAB at rest on focus, raises it while hovered and lowers it while pressed', + 'keeps the %s FAB at rest on focus, changes its elevation while hovered and restores it while pressed', async (type) => { const ref = React.createRef(); await render( From aa6137ced7c4c7ecc3483d1db2277a5330325f97 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 30 Oct 2026 15:05:46 +0100 Subject: [PATCH 14/25] test(fab): cover the blur fallback when focus can't move back The element stub always took focus, so nothing checked the blur after a restore attempt that the browser ignores. Make focus() a no-op on disconnected or unfocusable elements, as browsers do, and cover that case. --- src/components/__tests__/FAB.test.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 2b2efdd7fe..b7f15b8b35 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -513,9 +513,11 @@ describe('on web', () => { const createElement = ({ isConnected = true, + focusable = true, hiddenBy, }: { isConnected?: boolean; + focusable?: boolean; hiddenBy?: string; } = {}) => { const element = new View({}); @@ -523,8 +525,11 @@ describe('on web', () => { isConnected, closest: (selectors: string) => hiddenBy && selectors.includes(hiddenBy) ? {} : null, + // Like browsers, focus() does nothing on an element that can't take it. focus: jest.fn(() => { - activeElement = element; + if (isConnected && focusable) { + activeElement = element; + } }), }); }; @@ -621,6 +626,16 @@ describe('on web', () => { } ); + it("blurs a keyboard-focused FAB that hides when the previous element can't take focus", async () => { + const previous = createElement({ focusable: false }); + const { blur, hide } = await renderFocusedFAB(previous); + + await hide(); + + expect(previous.focus).toHaveBeenCalledWith({ preventScroll: true }); + expect(blur).toHaveBeenCalledTimes(1); + }); + it('blurs a FAB focused by a mouse click instead of moving focus back', async () => { focusVisible = false; const previous = createElement(); From b226ec639b4dcdf0e3450f1146871d40124f6b24 Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 6 Nov 2026 12:12:33 +0100 Subject: [PATCH 15/25] fix(fab): type the touchable ref for React Native 0.88 React Native 0.88 types View as a function component, so the ref type is React.ComponentRef, as main uses elsewhere. --- src/components/FAB/Shell.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/FAB/Shell.tsx b/src/components/FAB/Shell.tsx index 491f46ed0f..2ca0cf23a7 100644 --- a/src/components/FAB/Shell.tsx +++ b/src/components/FAB/Shell.tsx @@ -231,7 +231,7 @@ const Shell = ({ const theme = useInternalTheme(themeOverrides); const [hovered, setHovered] = React.useState(false); const [pressed, setPressed] = React.useState(false); - const touchableRef = React.useRef(null); + const touchableRef = React.useRef>(null); const previousFocusedElement = React.useRef(null); const hasHandler = hasTouchHandler({ onPress, onLongPress, onPressOut }); From 0018e803d54e9fdf548aafe75baab2fd165af9da Mon Sep 17 00:00:00 2001 From: likevy Date: Fri, 6 Nov 2026 12:14:03 +0100 Subject: [PATCH 16/25] test(fab): type the FAB test refs for React Native 0.88 Use React.ComponentRef for refs, cast to Reanimated's animated component shape where the tests read the animated style, as main does, and type the View mock instances the web focus tests stub. --- src/components/__tests__/FAB.test.tsx | 34 ++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index b7f15b8b35..882f5cbcc7 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { Platform, View } from 'react-native'; +import type { ViewProps } from 'react-native'; import { afterEach, @@ -280,14 +281,22 @@ describe('without a touch handler', () => { }); }); -const getStyle = (ref: React.RefObject) => { +const getStyle = ( + ref: React.RefObject | null> +) => { if (!ref.current) throw new Error('Expected FAB ref to be attached'); - return getAnimatedStyle(ref.current); + // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion + const animatedComponent = ref.current as unknown as { + props: Record; + }; + return getAnimatedStyle(animatedComponent); }; // Android exposes elevation as a plain number, so the direction is checkable // without the shadow tokens. -const getElevation = (ref: React.RefObject) => { +const getElevation = ( + ref: React.RefObject | null> +) => { const style = getStyle(ref); if (!('elevation' in style) || typeof style.elevation !== 'number') { throw new Error('Expected a numeric elevation'); @@ -323,7 +332,7 @@ it('hides an invisible FAB from accessibility and keyboard navigation without ma }); it('clears interaction elevation when a FAB is hidden and shown again', async () => { - const ref = React.createRef(); + const ref = React.createRef>(); const onPress = jest.fn(); const { rerender } = await render( { jest.replaceProperty(Platform, 'OS', platform); - const ref = React.createRef(); + const ref = React.createRef>(); await render( { jest.replaceProperty(Platform, 'OS', 'android'); - const ref = React.createRef(); + const ref = React.createRef>(); await render( { - const ref = React.createRef(); + const ref = React.createRef>(); const { rerender } = await render( { ); let activeElement: unknown; let focusVisible: boolean; - let fabElement: View | undefined; + // The jest View mock is a class component, so its instances have props. + type ViewMockInstance = { props: ViewProps; blur: () => void }; + let fabElement: ViewMockInstance | undefined; beforeEach(() => { jest.replaceProperty(Platform, 'OS', 'web'); @@ -488,7 +499,7 @@ describe('on web', () => { // The pressable view with the FAB's testID is the element that takes focus. Object.defineProperty(View.prototype, 'componentDidMount', { configurable: true, - value(this: View) { + value(this: ViewMockInstance) { if (this.props.testID === 'create') { fabElement = this; } @@ -520,7 +531,8 @@ describe('on web', () => { focusable?: boolean; hiddenBy?: string; } = {}) => { - const element = new View({}); + // Inherits from the View mock to pass the HTMLElement instanceof check. + const element: object = Object.create(View.prototype); return Object.assign(element, { isConnected, closest: (selectors: string) => @@ -559,7 +571,7 @@ describe('on web', () => { it.each(['icon', 'extended'] as const)( 'keeps the %s FAB at rest on focus, changes its elevation while hovered and restores it while pressed', async (type) => { - const ref = React.createRef(); + const ref = React.createRef>(); await render( type === 'icon' ? ( Date: Tue, 17 Nov 2026 09:26:29 +0100 Subject: [PATCH 17/25] fix(fab): keep a FAB without onPress a plain view Since #5071 a touchable with no touch handler and no disabled flag renders a plain View, so display-only content isn't announced as a disabled button. The shell always passed its press state handlers and disabled itself without onPress, which turned such a FAB back into a disabled button. Pass the press, hover and focus handlers only with an action and leave disabled to the caller. A hidden FAB with an action keeps its pressable mounted through those handlers, so the hide effect still sees the focused element, and it is hidden from assistive technology and the keyboard as before. --- src/components/FAB/Shell.tsx | 63 ++++++++++++++++----------- src/components/__tests__/FAB.test.tsx | 9 ++-- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/components/FAB/Shell.tsx b/src/components/FAB/Shell.tsx index 2ca0cf23a7..e956d56dd7 100644 --- a/src/components/FAB/Shell.tsx +++ b/src/components/FAB/Shell.tsx @@ -329,10 +329,11 @@ const Shell = ({ // stylesheet hides the browser's own outline there, so only the clip view's // ring shows, or only the outline in a browser without `:has()`. // - // Off when `disabled`, without a touch handler or while hidden: the inner - // TouchableRipple then can't be pressed, and a focused one unmounts without - // a blur reaching the hook. The public FAB has no `disabled`, so dropping - // the handlers is how an app turns it off. + // Off when `disabled` or without a touch handler: the inner TouchableRipple + // is then a plain View, and a focused one unmounts without a blur reaching + // the hook. The public FAB has no `disabled`, so dropping the handlers is how + // an app turns it off. Also off while hidden, which clears the focus state on + // native when the FAB hides while focused. const { target: focusTarget, ring: focusRing } = useFocusRing( disabled || !hasHandler || !visible, theme.colors.secondary, @@ -415,28 +416,40 @@ const Shell = ({ onPress={visible ? onPress : undefined} onLongPress={visible ? onLongPress : undefined} delayLongPress={delayLongPress} - disabled={disabled || !hasHandler} - accessible={visible} - focusable={visible && hasHandler} + disabled={disabled} + accessible={visible ? undefined : false} + focusable={visible ? undefined : false} tabIndex={visible ? undefined : -1} - onHoverIn={() => setHovered(true)} - onHoverOut={() => setHovered(false)} - onPressIn={() => setPressed(true)} - onPressOut={(event) => { - setPressed(false); - onPressOut?.(event); - }} - onFocus={(event) => { - if (Platform.OS === 'web') { - const previous = - 'relatedTarget' in event.nativeEvent - ? event.nativeEvent.relatedTarget - : null; - previousFocusedElement.current = - previous instanceof HTMLElement ? previous : null; - } - focusTarget.onFocus?.(event); - }} + // Only with a touch handler: a FAB without one is a plain View that + // takes no focus, and the press handlers alone would make it a + // control. They also keep a hidden FAB's touchable mounted without + // `onPress`, so the effect above still finds the focused element. + onHoverIn={hasHandler ? () => setHovered(true) : undefined} + onHoverOut={hasHandler ? () => setHovered(false) : undefined} + onPressIn={hasHandler ? () => setPressed(true) : undefined} + onPressOut={ + hasHandler + ? (event) => { + setPressed(false); + onPressOut?.(event); + } + : undefined + } + onFocus={ + hasHandler + ? (event) => { + if (Platform.OS === 'web') { + const previous = + 'relatedTarget' in event.nativeEvent + ? event.nativeEvent.relatedTarget + : null; + previousFocusedElement.current = + previous instanceof HTMLElement ? previous : null; + } + focusTarget.onFocus?.(event); + } + : undefined + } onBlur={focusTarget.onBlur} aria-label={ariaLabel} role={isWebImage ? 'img' : 'button'} diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 882f5cbcc7..50b66958f3 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -304,9 +304,10 @@ const getElevation = ( return style.elevation; }; -it('renders a FAB without onPress as a disabled button', async () => { +it('does not turn a FAB without onPress into a button', async () => { await render(); - expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); + expect(screen.getByLabelText('Create')).toBeOnTheScreen(); + expect(screen.queryByRole('button')).not.toBeOnTheScreen(); }); it('hides an invisible FAB from accessibility and keyboard navigation without marking it disabled', async () => { @@ -445,7 +446,9 @@ it('restores the resting elevation when a hovered FAB loses its action', async ( expect(getStyle(ref)).not.toEqual(resting); await rerender(); expect(getStyle(ref)).toEqual(resting); - expect(screen.getByRole('button', { name: 'Create' })).toBeDisabled(); + expect( + screen.queryByRole('button', { name: 'Create' }) + ).not.toBeOnTheScreen(); await rerender( {}} />); expect(getStyle(ref)).toEqual(resting); }); From e1e57ef08f2bfe99878e3d56e3d18824d73a4d61 Mon Sep 17 00:00:00 2001 From: likevy Date: Tue, 17 Nov 2026 09:26:30 +0100 Subject: [PATCH 18/25] test(fab): update the FAB snapshots Rename the tonal variant snapshots to the container variants, and record that a hidden FAB, extended FAB and menu trigger are aria-hidden, inaccessible, unfocusable and out of the tab order. --- .../__tests__/__snapshots__/FAB.test.tsx.snap | 437 +----------------- .../__snapshots__/FABExtended.test.tsx.snap | 4 +- .../__snapshots__/FABMenu.test.tsx.snap | 2 +- 3 files changed, 9 insertions(+), 434 deletions(-) diff --git a/src/components/__tests__/__snapshots__/FAB.test.tsx.snap b/src/components/__tests__/__snapshots__/FAB.test.tsx.snap index 48e7f74601..03e5c8476b 100644 --- a/src/components/__tests__/__snapshots__/FAB.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/FAB.test.tsx.snap @@ -376,6 +376,7 @@ exports[`renders FAB medium size 1`] = ` exports[`renders FAB transitioning to not visible 1`] = ` - - - - - - plus - - - - - -`; - -exports[`renders FAB with tonalSecondary variant 1`] = ` - - - - - - - plus - - - - - -`; - -exports[`renders FAB with tonalTertiary variant 1`] = ` - Date: Tue, 17 Nov 2026 09:26:46 +0100 Subject: [PATCH 19/25] docs(fab): use the container variant names in the migration guide The 5.x mapping, the sentence about which variants paint the container role and the diff example now name primaryContainer, secondaryContainer and tertiaryContainer instead of the tonal variants this PR renames. --- docs/6.x/docs/guides/migration.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/6.x/docs/guides/migration.md b/docs/6.x/docs/guides/migration.md index bb5821f1bb..6d0b583eb3 100644 --- a/docs/6.x/docs/guides/migration.md +++ b/docs/6.x/docs/guides/migration.md @@ -1266,18 +1266,18 @@ mutually exclusive options, use `SegmentedButtons`. #### `variant` -The variants changed meaning. In 5.x, `primary`, `secondary` and `tertiary` painted the container role, e.g. `primaryContainer`. In 6.x they paint the role itself, e.g. `primary`, and the new tonal variants paint the container role. So a FAB with an explicit `variant` looks different. To keep the 5.x colors: +The variants changed meaning. In 5.x, `primary`, `secondary` and `tertiary` painted the container role, e.g. `primaryContainer`. In 6.x they paint the role itself, e.g. `primary`, and the new `primaryContainer`, `secondaryContainer` and `tertiaryContainer` variants paint the container role. So a FAB with an explicit `variant` looks different. To keep the 5.x colors: -- **`primary`** (the 5.x default) → **`tonalPrimary`** (the 6.x default) -- **`secondary`** → **`tonalSecondary`** -- **`tertiary`** → **`tonalTertiary`** +- **`primary`** (the 5.x default) → **`primaryContainer`** (the 6.x default) +- **`secondary`** → **`secondaryContainer`** +- **`tertiary`** → **`tertiaryContainer`** - **`surface`** has no variant. Set `containerColor` and `contentColor` instead, e.g. to `theme.colors.surfaceContainerHigh` and `theme.colors.primary`. A FAB without a `variant` keeps its 5.x colors. ```diff - -+ ++ ``` #### `size` From 1a92e1ff70297efb33086d7a4f5f6a1d216b1677 Mon Sep 17 00:00:00 2001 From: likevy Date: Tue, 17 Nov 2026 09:28:16 +0100 Subject: [PATCH 20/25] test(fab): name React Native 0.88 in the native hover comment The hover gating in Pressability is unchanged in 0.88: iOS and Android get no hover handlers unless shouldPressibilityUseW3CPointerEventsForHover is on, and it defaults off. --- src/components/__tests__/FAB.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 50b66958f3..da18115bf5 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -374,7 +374,7 @@ it('uses the shared FAB hover elevation for the menu trigger', async () => { expect(JSON.stringify(toJSON())).toBe(before); }); -// React Native 0.85 sends no hover events on iOS or Android by default. These +// React Native 0.88 sends no hover events on iOS or Android by default. These // only check that the elevation logic itself has no platform check. it.each(['ios', 'android'] as const)( 'keeps the resting elevation on focus and follows hover and press events when Platform.OS is %s', From 01744920a0a7dd70cb349846418a4f574c311e89 Mon Sep 17 00:00:00 2001 From: likevy Date: Wed, 18 Nov 2026 11:25:09 +0100 Subject: [PATCH 21/25] perf(fab): track the press only while the FAB is hovered The pressed elevation matches the resting one, so the press state only matters on a hovered FAB. iOS and Android send no hover events by default, so tracking every press re-rendered the FAB twice per tap for nothing. Set the press state only while the FAB is hovered. Refs hold the hover and press state between events: react-native-web runs both press handlers before a render for a click under 50 ms, and a press can start before the pointer arrives, e.g. from the keyboard. --- src/components/FAB/Shell.tsx | 52 +++++++++++++++----- src/components/__tests__/FAB.test.tsx | 69 ++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 13 deletions(-) diff --git a/src/components/FAB/Shell.tsx b/src/components/FAB/Shell.tsx index e956d56dd7..01fe53496e 100644 --- a/src/components/FAB/Shell.tsx +++ b/src/components/FAB/Shell.tsx @@ -233,6 +233,8 @@ const Shell = ({ const [pressed, setPressed] = React.useState(false); const touchableRef = React.useRef>(null); const previousFocusedElement = React.useRef(null); + const hoveredRef = React.useRef(false); + const pressingRef = React.useRef(false); const hasHandler = hasTouchHandler({ onPress, onLongPress, onPressOut }); @@ -364,6 +366,8 @@ const Shell = ({ if (target === document.activeElement) target.blur(); } } + hoveredRef.current = false; + pressingRef.current = false; setHovered(false); setPressed(false); } @@ -371,11 +375,41 @@ const Shell = ({ React.useEffect(() => { if (!hasHandler) { + hoveredRef.current = false; + pressingRef.current = false; setHovered(false); setPressed(false); } }, [hasHandler]); + // The pressed elevation matches the resting one, so a press only shows on a + // hovered FAB, and `pressed` is set only then. iOS and Android send no hover + // events by default, so a tap there doesn't re-render the FAB itself. The + // refs hold the pointer state between events: a quick click on web runs both + // press handlers before a render, and a press can start before the hover. + const handleHoverIn = () => { + hoveredRef.current = true; + setHovered(true); + if (pressingRef.current) setPressed(true); + }; + + const handleHoverOut = () => { + hoveredRef.current = false; + setHovered(false); + setPressed(false); + }; + + const handlePressIn = () => { + pressingRef.current = true; + if (hoveredRef.current) setPressed(true); + }; + + const handlePressOut = (event: GestureResponderEvent) => { + pressingRef.current = false; + if (hoveredRef.current) setPressed(false); + onPressOut?.(event); + }; + // Without a handler the touchable drops the button role, and on web that // renders role="presentation", which can't carry a name. A labelled // icon-only FAB that does nothing is an image there, named by its label. @@ -423,18 +457,12 @@ const Shell = ({ // Only with a touch handler: a FAB without one is a plain View that // takes no focus, and the press handlers alone would make it a // control. They also keep a hidden FAB's touchable mounted without - // `onPress`, so the effect above still finds the focused element. - onHoverIn={hasHandler ? () => setHovered(true) : undefined} - onHoverOut={hasHandler ? () => setHovered(false) : undefined} - onPressIn={hasHandler ? () => setPressed(true) : undefined} - onPressOut={ - hasHandler - ? (event) => { - setPressed(false); - onPressOut?.(event); - } - : undefined - } + // `onPress` or `onLongPress`, so the effect above still finds the + // focused element. + onHoverIn={hasHandler ? handleHoverIn : undefined} + onHoverOut={hasHandler ? handleHoverOut : undefined} + onPressIn={hasHandler ? handlePressIn : undefined} + onPressOut={hasHandler ? handlePressOut : undefined} onFocus={ hasHandler ? (event) => { diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index da18115bf5..c0362a45b6 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -15,7 +15,7 @@ import * as Reanimated from 'react-native-reanimated'; import { getAnimatedStyle } from 'react-native-reanimated'; import PaperProvider from '../../core/PaperProvider'; -import { render, screen } from '../../test-utils'; +import { act, render, screen } from '../../test-utils'; import FAB from '../FAB'; import Tooltip from '../Tooltip/Tooltip'; @@ -409,6 +409,73 @@ it.each(['ios', 'android'] as const)( } ); +it('does not re-render the FAB shell for a press without hover', async () => { + const onRender = jest.fn(); + await render( + + {}} /> + + ); + const fab = screen.getByRole('button', { name: 'Create' }); + onRender.mockClear(); + + // fireEvent calls the shell's press handlers directly. On iOS a real tap + // still re-renders the touchable for its own press feedback. + await fireEvent(fab, 'pressIn'); + await fireEvent(fab, 'pressOut', { nativeEvent: {} }); + + expect(onRender).not.toHaveBeenCalled(); +}); + +// react-native-web runs both press handlers before a render when a click +// takes less than 50 ms, e.g. a tap-to-click on a trackpad. +it('returns a hovered FAB to its hover elevation after a quick click', async () => { + const ref = React.createRef>(); + await render( + {}} + /> + ); + const fab = screen.getByRole('button', { name: 'Create' }); + await fireEvent(fab, 'hoverIn'); + const hovered = getStyle(ref); + + // The outer act holds the render back until both handlers have run, as + // react-native-web does for a quick click. + await act(async () => { + await fireEvent(fab, 'pressIn'); + await fireEvent(fab, 'pressOut', { nativeEvent: {} }); + }); + + expect(getStyle(ref)).toEqual(hovered); +}); + +it('shows the pressed elevation when the pointer arrives during a press', async () => { + const ref = React.createRef>(); + await render( + {}} + /> + ); + const fab = screen.getByRole('button', { name: 'Create' }); + const resting = getStyle(ref); + + // e.g. a keyboard press, with the mouse moving onto the FAB before release + await fireEvent(fab, 'pressIn'); + await fireEvent(fab, 'hoverIn'); + expect(getStyle(ref)).toEqual(resting); + await fireEvent(fab, 'pressOut', { nativeEvent: {} }); + expect(getStyle(ref)).not.toEqual(resting); +}); + it('raises the elevation while hovered and lowers it while pressed when Platform.OS is android', async () => { jest.replaceProperty(Platform, 'OS', 'android'); const ref = React.createRef>(); From cd5c7d1111e1c5b7e642faea06b9ac1247168f39 Mon Sep 17 00:00:00 2001 From: likevy Date: Wed, 18 Nov 2026 11:25:11 +0100 Subject: [PATCH 22/25] test(fab): check that onPressOut fires alongside the press state The shell clears its own press state in onPressOut and also calls the onPressOut that #5172 forwards. Cover a hovered FAB's release doing both. --- src/components/__tests__/FAB.test.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index c0362a45b6..90a83ffe22 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -476,6 +476,31 @@ it('shows the pressed elevation when the pointer arrives during a press', async expect(getStyle(ref)).not.toEqual(resting); }); +it('calls onPressOut and drops the pressed elevation when a hovered FAB is released', async () => { + const ref = React.createRef>(); + const onPressOut = jest.fn(); + await render( + {}} + onPressOut={onPressOut} + /> + ); + const fab = screen.getByRole('button', { name: 'Create' }); + + await fireEvent(fab, 'hoverIn'); + const hovered = getStyle(ref); + await fireEvent(fab, 'pressIn'); + expect(getStyle(ref)).not.toEqual(hovered); + await fireEvent(fab, 'pressOut', { nativeEvent: {} }); + + expect(onPressOut).toHaveBeenCalledWith({ nativeEvent: {} }); + expect(getStyle(ref)).toEqual(hovered); +}); + it('raises the elevation while hovered and lowers it while pressed when Platform.OS is android', async () => { jest.replaceProperty(Platform, 'OS', 'android'); const ref = React.createRef>(); From 85f54bb783cfac05fd90d7224f9159ac09ea0ba0 Mon Sep 17 00:00:00 2001 From: likevy Date: Wed, 18 Nov 2026 11:25:11 +0100 Subject: [PATCH 23/25] test(fab): cover a FAB that hides mid-press A FAB that hides during a press drops its long press but still reports the release, so a Tooltip's touch end still fires. Hold the press through Pressability's own timers. --- src/components/__tests__/FAB.test.tsx | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index 90a83ffe22..f1f593d3d9 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -332,6 +332,39 @@ it('hides an invisible FAB from accessibility and keyboard navigation without ma expect(onPress).not.toHaveBeenCalled(); }); +// Drives Pressability itself, so the press is held through its timers. +const touch = { + nativeEvent: { touches: [], changedTouches: [], identifier: 1 }, + currentTarget: { measure: () => {} }, + persist: () => {}, +}; + +it('ignores a long press once the FAB hides mid-press but still reports the release', async () => { + const onPress = jest.fn(); + const onLongPress = jest.fn(); + const onPressOut = jest.fn(); + const fabProps = { + icon: 'plus', + 'aria-label': 'Create', + onPress, + onLongPress, + onPressOut, + delayLongPress: 300, + }; + const { rerender } = await render(); + const fab = screen.getByRole('button', { name: 'Create' }); + + await fireEvent(fab, 'responderGrant', touch); + await rerender(); + await act(() => jest.advanceTimersByTime(500)); + await fireEvent(fab, 'responderRelease', touch); + await act(() => jest.advanceTimersByTime(500)); + + expect(onLongPress).not.toHaveBeenCalled(); + expect(onPress).not.toHaveBeenCalled(); + expect(onPressOut).toHaveBeenCalledTimes(1); +}); + it('clears interaction elevation when a FAB is hidden and shown again', async () => { const ref = React.createRef>(); const onPress = jest.fn(); From 9770bb196340529a232e757e2c2f9421e39bc6b0 Mon Sep 17 00:00:00 2001 From: likevy Date: Wed, 18 Nov 2026 11:25:12 +0100 Subject: [PATCH 24/25] test(fab): cover a press cut short by hiding or losing the action Hiding the FAB or dropping its handlers ends a press without a release, so the shell resets its hover and press refs. Check that a FAB that comes back shows the hover elevation, not the pressed one. --- src/components/__tests__/FAB.test.tsx | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index f1f593d3d9..fec1586863 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -365,6 +365,37 @@ it('ignores a long press once the FAB hides mid-press but still reports the rele expect(onPressOut).toHaveBeenCalledTimes(1); }); +it.each([ + ['loses its action', { onPress: undefined }], + ['hides', { visible: false }], +])( + 'shows the hover elevation again after a FAB that %s mid-press comes back', + async (_, interruption) => { + const ref = React.createRef>(); + const fabProps = { + ref, + style: {}, + icon: 'plus', + 'aria-label': 'Create', + onPress: () => {}, + }; + const { rerender } = await render(); + const resting = getStyle(ref); + + // The interruption ends the press without a release. + await fireEvent( + screen.getByRole('button', { name: 'Create' }), + 'responderGrant', + touch + ); + await rerender(); + await rerender(); + await fireEvent(screen.getByRole('button', { name: 'Create' }), 'hoverIn'); + + expect(getStyle(ref)).not.toEqual(resting); + } +); + it('clears interaction elevation when a FAB is hidden and shown again', async () => { const ref = React.createRef>(); const onPress = jest.fn(); From 4568f7ae9691023657be9602946e7181b8fbbee4 Mon Sep 17 00:00:00 2001 From: likevy Date: Wed, 18 Nov 2026 11:25:13 +0100 Subject: [PATCH 25/25] test(fab): name the handler-less FAB test after any touch handler Since #5172 a FAB with only onLongPress or onPressOut is a button too. --- src/components/__tests__/FAB.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/__tests__/FAB.test.tsx b/src/components/__tests__/FAB.test.tsx index fec1586863..8eb91a1efa 100644 --- a/src/components/__tests__/FAB.test.tsx +++ b/src/components/__tests__/FAB.test.tsx @@ -304,7 +304,7 @@ const getElevation = ( return style.elevation; }; -it('does not turn a FAB without onPress into a button', async () => { +it('does not turn a FAB without a touch handler into a button', async () => { await render(); expect(screen.getByLabelText('Create')).toBeOnTheScreen(); expect(screen.queryByRole('button')).not.toBeOnTheScreen();