Repository navigation
feat: Complete FAB Menu behavior and web adaptation - #5170
alpharius-ck wants to merge 11 commits into
Conversation
|
Found potential problems with the pull request:
|
# Conflicts: # src/components/FAB/Shell.tsx
The previous merge of main kept the old versions of most files that changed on main. Bring the tree to main plus the FAB menu changes so the PR only shows the FAB files. Type the FAB refs with ComponentRef<typeof View> and ComponentRef<typeof ScrollView>, as main does, since View and ScrollView are no longer instance types on React Native 0.88. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the videos @likevy, they look good. After I updated the branch, Typecheck and Build package fail: React Native 0.88 (from #5167) now types type KeyboardEvent = {
nativeEvent: { key: string; repeat?: boolean | undefined };
preventDefault: () => void;
};Could you push that? Then I'll do the last checks and merge. |
sure - would do asap |
|
@Doberjohn branch is working correctly with RN 0.88 |
Resolve FAB.Menu against the shared `useFocusRing` from main, and make the menu a proper overlay: Escape, Android back and the iOS escape gesture dismiss it, focus moves to the first item on open and returns to the trigger on close. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jacekAtCK
left a comment
There was a problem hiding this comment.
Requesting changes for the rebase on main and the keyboard issues on web. Details are inline.
| // first mount doesn't animate unexpectedly. | ||
| const scaleX = useSharedValue(expanded ? 1 : 0); | ||
| const alpha = useSharedValue(expanded ? 1 : 0); | ||
| const { scale } = theme.animation; |
There was a problem hiding this comment.
#5235 removed theme.animation.scale from main, so after the rebase this line and lines 308 and 510 should fail typecheck. Could you replace the * scale parts with useReduceMotion(), as other components on main do?
| > | ||
| {overlay} | ||
| <TouchableRipple | ||
| ref={buttonRef} |
There was a problem hiding this comment.
Main now passes a web-only touchableRef to this same TouchableRipple to blur and restore focus when the FAB hides, so it conflicts with buttonRef here. Could you merge both refs into one during the rebase?
| onHoverOut={() => setHovered(false)} | ||
| onPressIn={() => setPressed(true)} | ||
| onPressOut={() => setPressed(false)} | ||
| role={Platform.OS === 'web' ? 'menuitem' : 'button'} |
There was a problem hiding this comment.
Space does nothing on a focused item on web (Enter works), because RNW presses on Space only for role="button". Could you add useSpaceKeyPress to the item, as Checkbox does?
| // `aria-hidden` and `pointerEvents` don't take collapsed items | ||
| // out of the tab order. | ||
| focusable={expanded} | ||
| tabIndex={expanded ? 0 : -1} |
There was a problem hiding this comment.
On web every item is a Tab stop, Tab leaves the menu while it stays open, and ArrowUp from the first item or End jumps to the close button, which is outside role="menu". Could we use a roving tabindex with aria-labelledby on the menu, or drop the menu and menuitem roles and use buttons in a labelled group?
| @@ -552,12 +672,145 @@ const Menu = ({ | |||
|
|
|||
| const effectiveExpanded = triggerVisible && expanded; | |||
There was a problem hiding this comment.
If the FAB hides while the menu is open, onDismiss is not called, so parent keeps expanded=true. When I turned "Show FAB" off and on, the menu opened again by itself and focus jumped to "Send", so could we call onDismiss when the trigger hides?
| expanded: boolean; | ||
| /** | ||
| * Called when the user taps the close button or taps an item. | ||
| * Called when the menu should close: the user taps the close button, an |
There was a problem hiding this comment.
Nothing closes the menu on an outside press (I clicked outside on web and it stayed open), and main's migration guide says on purpose that it does not. Could we drop "or outside the menu" here and "Pressing outside the menu" on line 626?
|
|
||
| // The screen reader is sent to an element, which the test can only tell | ||
| // apart by the `testID` it was given. | ||
| const focusedTestID = () => { |
There was a problem hiding this comment.
Could we drop the eslint-disable and the cast here? toHaveBeenCalledWith(expect.objectContaining({ props: expect.objectContaining({ testID: 'item-0' }) }), 'focus') should check the same thing.
| pressed: stateOpacity.pressed, | ||
| } as const satisfies Record<Interaction, number>; | ||
|
|
||
| export const webNoHoverTint: ViewStyle = { backgroundColor: 'transparent' }; |
There was a problem hiding this comment.
nit: is webNoHoverTint a token or more like a style? Maybe it should be in Menu itself?
Motivation
FAB.Menudid not follow the Material 3 spec or the other v6 components in a few ways. On web it did not tell assistive technology whether it was open. Collapsed items stayed in the tab order and the accessibility tree. Items had no hover, focus or press feedback, and a menu taller than the screen could not scroll.This PR fixes those. Dismissal (Escape, Android back, outside press, screen reader escape) and focus handling (focus on open, restore on close) are intentionally left out and belong to the overlay work in #5127. A follow-up will wire
FAB.Menuinto that portal stack. Until then, the menu closes only through its trigger and items, as onmain.Builds on #5110 (variant rename). It also covers the
aria-expandedchange from #5151, so one of the two should be dropped when they land.Related issue
https://app.notion.com/p/callstack/Complete-FAB-Menu-behavior-and-web-adaptation-3ac5d027c0f8806ba4f8f5a8cc061eac?v=3285d027c0f880a68ccb000c1ce3c56e&source=copy_link
Screenshots / Videos
Test plan
Use the example app:
FAB→menu(yarn example web,yarn example ios,yarn example android).Web
aria-expanded="false"andaria-haspopup="menu". After opening, it hasaria-expanded="true", and the items container hasrole="menu".iOS / Android
adb shell wm size 1080x1000), the items scroll to the last one. Reopening starts at the top.