-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(react-menu): replace keydown handlers by useARIAButtonShorthand on MenuItem #24738
feat(react-menu): replace keydown handlers by useARIAButtonShorthand on MenuItem #24738
Conversation
📊 Bundle size reportUnchanged fixtures
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 44ab882:
|
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: e0a0ab1481d0fb64f2a9804376ad17e4f4f8ea01 (build) |
Perf Analysis (
|
Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
---|---|---|---|---|---|
Avatar | mount | 1308 | 1303 | 5000 | |
Button | mount | 954 | 946 | 5000 | |
FluentProvider | mount | 1579 | 1573 | 5000 | |
FluentProviderWithTheme | mount | 641 | 640 | 10 | |
FluentProviderWithTheme | virtual-rerender | 591 | 592 | 10 | |
FluentProviderWithTheme | virtual-rerender-with-unmount | 633 | 639 | 10 | |
MakeStyles | mount | 1895 | 1892 | 50000 | |
SpinButton | mount | 2563 | 2526 | 5000 |
3435766
to
59ddb12
Compare
Blocked by #24742 |
cc9036d
to
8f00133
Compare
packages/react-components/react-menu/src/components/Menu/Menu.types.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItem/useMenuItemStyles.ts
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItem/useMenuItemStyles.ts
Outdated
Show resolved
Hide resolved
@@ -84,7 +84,8 @@ export const TestOverflowMenuItem: React.FC<TestOverflowMenuItemProps> = props = | |||
return null; | |||
} | |||
|
|||
return <MenuItem {...rest}>Item {id}</MenuItem>; | |||
// As an union between button props and div props may be conflicting, casting is required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that users that wrap the MenuItem
component and spread props also need to cast, even if the type extends from MenuItemProps
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! that is true for Button
also, upper casting is required before spreading.
c5996e4
to
b60a745
Compare
packages/react-components/react-menu/src/components/Menu/Menu.types.ts
Outdated
Show resolved
Hide resolved
This PR also fixes #24680 @bsunderhus can you add it to the description ? |
packages/react-components/react-tabs/src/stories/Tabs/TabListWithOverflow.stories.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItemRadio/MenuItemRadio.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItemRadio/MenuItemRadio.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItemRadio/useMenuItemRadio.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItemCheckbox/MenuItemCheckbox.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItem/MenuItem.types.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItem/useMenuItem.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItem/MenuItem.test.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-menu/src/components/MenuItemCheckbox/useMenuItemCheckbox.tsx
Outdated
Show resolved
Hide resolved
…types.ts Co-authored-by: ling1726 <lingfangao@hotmail.com>
0c21fd0
to
9964ffd
Compare
b115e33
to
44ab882
Compare
@@ -54,7 +55,7 @@ const shimMenuHeaderProps = (props: IContextualMenuItem): MenuGroupHeaderProps = | |||
export const MenuItemShim = (props: IContextualMenuItem) => { | |||
if (props.itemType === ContextualMenuItemType.Divider) { | |||
const shimProps = shimMenuItemProps(props); | |||
return <MenuDivider {...shimProps} />; | |||
return <MenuDivider {...(shimProps as MenuDividerProps)} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how the changes you made caused this cast to be required, but it won't hurt :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The casting is required since spreading of props can be conflicting when using discriminated unions. Basically there's no way to know if we're spreading button
props or a
props, so we need to explicitly upper cast to ensure it's a generic that represents both.
* master: (28 commits) fix: use trigger prop for aria-haspopup (microsoft#24794) chore(react-dialog): scaffold DialogContent component (microsoft#24844) chore: Northstar screener should read from screenerStates.json (microsoft#24848) applying package updates (web components) Standardize focus treatment (microsoft#24771) Divider - allow default prop override (microsoft#24840) GroupedList: fix virtualization (unstable preview) (microsoft#24460) fix: Add explicit children prop to TeachingBubble to support React 18 (microsoft#24823) feat: Adds `visible` prop to `TableCellActions` (microsoft#24831) [Northstar][Dropdown] Fix styling mutation when merging themes (microsoft#24787) fix: export `tableCellActionsClassNames` from unstable (microsoft#24830) bugfix(react-dialog): Adds color style to DialogSurface (microsoft#24832) applying package updates Prevent group toggling from selecting the whole group (microsoft#24822) feat(react-textarea): Add shadow variant of filled appearance (microsoft#24512) applying package updates Adding lib-commonjs top-level entries to exports map (microsoft#24792) Created shim packages (microsoft#24780) feat(react-menu): replace keydown handlers by useARIAButtonShorthand on MenuItem (microsoft#24738) fix: update version mismatches triggered by v9 release (microsoft#24812) ...
This is likely a regression from #24738. Specifically, the removal of `shouldHandleKeyboardRef` from useMenu.tsx is causing it to always call `state.triggerRef.current?.focus()` when mounted.
…oft#25016) This is likely a regression from microsoft#24738. Specifically, the removal of `shouldHandleKeyboardRef` from useMenu.tsx is causing it to always call `state.triggerRef.current?.focus()` when mounted.
Current Behavior
MenuItem
currently provides its own customkeydown
handlers to ensure button functionality.New Behavior
useARIAButtonShorthand
instead of implementing it's own handlersMenuItem
,MenuItemCheckbox
andMenuItemRadio
state.Related Issue(s)
While pressing
Space
the oficial functionality of a nativebutton
is to emit a click event onkeyup
. take the example bellow:Meanwhile
Button
behaves as a proper nativebutton
and emits click onkeyup
,MenuItem
will close onSpace
keydown
, meaning that as soon as you pressSpace
onMenuItem
theMenu
will close onkeydown
and immediately open up again as soon asSpace
is release emitting akeyup
event.Fixes #24680