Repository navigation
fix(fab)!: align MD3 variants and interaction states - #5110
Conversation
|
We've got conflicts @likevy |
ea20e26 to
b200183
Compare
There was a problem hiding this comment.
Review by Claude
The PR description no longer matches the code. It still says surface is added, hover elevation is web only, the menu trigger does not rise, and an explicit shell elevation is kept. The second commit changed all four. Please update it so the description matches what ships. (via Claude, verify if it makes sense)
satya164
left a comment
There was a problem hiding this comment.
Review by Claude
See the inline comments. (via Claude, verify if it makes sense)
b200183 to
55b9ea9
Compare
|
We've decided the variant rename lands in 6.0 (D11 in #5150), and your latest push already matches it: no Two small things:
After that it's ready for a full review. |
95f1d90 to
2c6a466
Compare
xdimota7x
left a comment
There was a problem hiding this comment.
Thanks for the updates! All earlier review threads look addressed. I merged this locally with current main and verified on web: the hover elevation goes 3 → 4 and back to 3 when pressed for the icon, extended and menu FABs, a hidden FAB is skipped by Tab and the accessibility tree, and keyboard focus returns to the previous element on hide. Typecheck, lint and tests pass.
Two things before it can be merged:
- Migration guide: #5184 added a full
### FABsection on main, and its#### variantpart still maps 5.x variants totonalPrimary,tonalSecondaryandtonalTertiary. After merging, the guide would have two FAB sections, one recommending names this PR removes. Could you drop the new section and instead update thevariantbullets and diff example in the existing one to the*Containernames? The rest of your section (the silent-change note,surface,color→ contentColor) is already covered there. - Rebase after #5107: #5107 replaces the FAB's
useFocusRingwith a shared hook ({ target, ring }). The hide effect'sonBlur()call and theonFocuswrapper will need re-wiring to it.
2c6a466 to
41c9c63
Compare
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.
Effects do not run during server rendering and document always exists on web, so the check never fails.
The menu trigger is an icon-only FAB, so without a label it is announced as an unnamed button.
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.
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.
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.
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.
MD3 keeps a focused FAB at level 3. Without this step, folding focus into the hover state would still pass the elevation tests.
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.
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.
React Native 0.88 types View as a function component, so the ref type is React.ComponentRef<typeof View>, as main uses elsewhere.
Use React.ComponentRef<typeof View> 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.
Since callstack#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.
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.
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.
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.
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.
The shell clears its own press state in onPressOut and also calls the onPressOut that callstack#5172 forwards. Cover a hovered FAB's release doing both.
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.
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.
Since callstack#5172 a FAB with only onLongPress or onPressOut is a button too.
8ff9e9a to
4568f7a
Compare
The 6.x migration guide gets the entries that were missing for the Dialog (#5072), FAB (#5110) and TextInput (#5111) changes. - Dialog: the Portal sample shows the 5.x form and the prop-based API section says `children` is gone. New sections cover `scrollable` in place of `Dialog.ScrollArea`, a function `icon` for the icon's color and size, plain views in place of `Dialog.Content` and `Dialog.Actions` outside a Dialog, and the layout changes. The actions row style has no replacement, and the guide says so. - FAB: what `visible={false}` now does, and that tests need `includeHiddenElements` to find a hidden FAB. - TextInput: a disabled field is always read-only. - Focus indicator: the Appbar sentence now says the parts read the bar's `theme` from context (#5218) and links to that section. Two notes for apps written against a 6.0 alpha cover the dialog's top spacing and the single dim of a disabled field; neither changes anything for 5.x users. Part of #4991.
…5276) The 6.0.0-alpha.3 guide told apps to use the FAB variants `tonalPrimary`, `tonalSecondary` and `tonalTertiary`. #5110 renamed them `primaryContainer`, `secondaryContainer` and `tertiaryContainer`, with the same colors and no aliases, so JavaScript code that still passes an old name throws at render unless it sets `containerColor`. The FAB `variant` section now has an "If your app was written for a 6.0 alpha build" line and a diff for the rename, like the guide's other notes for alpha apps. Nothing changes for 5.x users. Part of #4991.
Motivation
FAB presets didn't use MD3 role names and hover elevation was unused.
tonalPrimaryis nowprimaryContainer, same for secondary and tertiary.Related issue
FAB review checklist.
Screenshots / Videos
Test plan
In the FAB example: