-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: Context menu close should restore focus #29290
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
Merged
ling1726
merged 4 commits into
microsoft:master
from
ling1726:fix/context-menu-focus-restore
Sep 26, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-menu-afb66643-49cf-4a58-a947-2645694572a3.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "fix: Context menu close should restore focus", | ||
| "packageName": "@fluentui/react-menu", | ||
| "email": "lingfangao@hotmail.com", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
packages/react-components/react-menu/stories/Menu/MenuDefault.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/react-components/react-message-bar-preview/src/Messagebar.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/Messagebar/index'; |
18 changes: 18 additions & 0 deletions
18
.../react-components/react-message-bar-preview/src/components/Messagebar/Messagebar.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
| import { Messagebar } from './Messagebar'; | ||
|
|
||
| describe('Messagebar', () => { | ||
| isConformant({ | ||
| Component: Messagebar, | ||
| displayName: 'Messagebar', | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<Messagebar>Default Messagebar</Messagebar>); | ||
| expect(result.container).toMatchSnapshot(); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-message-bar-preview/src/components/Messagebar/Messagebar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as React from 'react'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import { useMessagebar_unstable } from './useMessagebar'; | ||
| import { renderMessagebar_unstable } from './renderMessagebar'; | ||
| import { useMessagebarStyles_unstable } from './useMessagebarStyles.styles'; | ||
| import type { MessagebarProps } from './Messagebar.types'; | ||
|
|
||
| /** | ||
| * Messagebar component - TODO: add more docs | ||
| */ | ||
| export const Messagebar: ForwardRefComponent<MessagebarProps> = React.forwardRef((props, ref) => { | ||
| const state = useMessagebar_unstable(props, ref); | ||
|
|
||
| useMessagebarStyles_unstable(state); | ||
| return renderMessagebar_unstable(state); | ||
| }); | ||
|
|
||
| Messagebar.displayName = 'Messagebar'; |
17 changes: 17 additions & 0 deletions
17
.../react-components/react-message-bar-preview/src/components/Messagebar/Messagebar.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
|
||
| export type MessagebarSlots = { | ||
| root: Slot<'div'>; | ||
| }; | ||
|
|
||
| /** | ||
| * Messagebar Props | ||
| */ | ||
| export type MessagebarProps = ComponentProps<MessagebarSlots> & {}; | ||
|
|
||
| /** | ||
| * State used in rendering Messagebar | ||
| */ | ||
| export type MessagebarState = ComponentState<MessagebarSlots>; | ||
| // TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from MessagebarProps. | ||
| // & Required<Pick<MessagebarProps, 'propName'>> |
11 changes: 11 additions & 0 deletions
11
...eact-message-bar-preview/src/components/Messagebar/__snapshots__/Messagebar.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Messagebar renders a default state 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-Messagebar" | ||
| > | ||
| Default Messagebar | ||
| </div> | ||
| </div> | ||
| `; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-message-bar-preview/src/components/Messagebar/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export * from './Messagebar'; | ||
| export * from './Messagebar.types'; | ||
| export * from './renderMessagebar'; | ||
| export * from './useMessagebar'; | ||
| export * from './useMessagebarStyles.styles'; |
15 changes: 15 additions & 0 deletions
15
...react-components/react-message-bar-preview/src/components/Messagebar/renderMessagebar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /** @jsxRuntime automatic */ | ||
| /** @jsxImportSource @fluentui/react-jsx-runtime */ | ||
|
|
||
| import { assertSlots } from '@fluentui/react-utilities'; | ||
| import type { MessagebarState, MessagebarSlots } from './Messagebar.types'; | ||
|
|
||
| /** | ||
| * Render the final JSX of Messagebar | ||
| */ | ||
| export const renderMessagebar_unstable = (state: MessagebarState) => { | ||
| assertSlots<MessagebarSlots>(state); | ||
|
|
||
| // TODO Add additional slots in the appropriate place | ||
| return <state.root />; | ||
| }; |
31 changes: 31 additions & 0 deletions
31
...ges/react-components/react-message-bar-preview/src/components/Messagebar/useMessagebar.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import * as React from 'react'; | ||
| import { getNativeElementProps, slot } from '@fluentui/react-utilities'; | ||
| import type { MessagebarProps, MessagebarState } from './Messagebar.types'; | ||
|
|
||
| /** | ||
| * Create the state required to render Messagebar. | ||
| * | ||
| * The returned state can be modified with hooks such as useMessagebarStyles_unstable, | ||
| * before being passed to renderMessagebar_unstable. | ||
| * | ||
| * @param props - props from this instance of Messagebar | ||
| * @param ref - reference to root HTMLElement of Messagebar | ||
| */ | ||
| export const useMessagebar_unstable = (props: MessagebarProps, ref: React.Ref<HTMLElement>): MessagebarState => { | ||
| return { | ||
| // TODO add appropriate props/defaults | ||
| components: { | ||
| // TODO add each slot's element type or component | ||
| root: 'div', | ||
| }, | ||
| // TODO add appropriate slots, for example: | ||
| // mySlot: resolveShorthand(props.mySlot), | ||
| root: slot.always( | ||
| getNativeElementProps('div', { | ||
| ref, | ||
| ...props, | ||
| }), | ||
| { elementType: 'div' }, | ||
| ), | ||
| }; | ||
| }; |
33 changes: 33 additions & 0 deletions
33
...ponents/react-message-bar-preview/src/components/Messagebar/useMessagebarStyles.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { makeStyles, mergeClasses } from '@griffel/react'; | ||
| import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
| import type { MessagebarSlots, MessagebarState } from './Messagebar.types'; | ||
|
|
||
| export const messagebarClassNames: SlotClassNames<MessagebarSlots> = { | ||
| root: 'fui-Messagebar', | ||
| // TODO: add class names for all slots on MessagebarSlots. | ||
| // Should be of the form `<slotName>: 'fui-Messagebar__<slotName>` | ||
| }; | ||
|
|
||
| /** | ||
| * Styles for the root slot | ||
| */ | ||
| const useStyles = makeStyles({ | ||
| root: { | ||
| // TODO Add default styles for the root element | ||
| }, | ||
|
|
||
| // TODO add additional classes for different states and/or slots | ||
| }); | ||
|
|
||
| /** | ||
| * Apply styling to the Messagebar slots based on the state | ||
| */ | ||
| export const useMessagebarStyles_unstable = (state: MessagebarState): MessagebarState => { | ||
| const styles = useStyles(); | ||
| state.root.className = mergeClasses(messagebarClassNames.root, styles.root, state.root.className); | ||
|
|
||
| // TODO Add class names to slots, for example: | ||
| // state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className); | ||
|
|
||
| return state; | ||
| }; |
9 changes: 8 additions & 1 deletion
9
packages/react-components/react-message-bar-preview/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| export {}; | ||
| export { | ||
| Messagebar, | ||
| messagebarClassNames, | ||
| renderMessagebar_unstable, | ||
| useMessagebarStyles_unstable, | ||
| useMessagebar_unstable, | ||
| } from './Messagebar'; | ||
| export type { MessagebarProps, MessagebarSlots, MessagebarState } from './Messagebar'; |
5 changes: 5 additions & 0 deletions
5
...ponents/react-message-bar-preview/stories/Messagebar/MessagebarBestPractices.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ## Best practices | ||
|
|
||
| ### Do | ||
|
|
||
| ### Don't |
4 changes: 4 additions & 0 deletions
4
...act-components/react-message-bar-preview/stories/Messagebar/MessagebarDefault.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import * as React from 'react'; | ||
| import { Messagebar, MessagebarProps } from '@fluentui/react-message-bar-preview'; | ||
|
|
||
| export const Default = (props: Partial<MessagebarProps>) => <Messagebar {...props} />; |
Empty file.
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-message-bar-preview/stories/Messagebar/index.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Messagebar } from '@fluentui/react-message-bar-preview'; | ||
|
|
||
| import descriptionMd from './MessagebarDescription.md'; | ||
| import bestPracticesMd from './MessagebarBestPractices.md'; | ||
|
|
||
| export { Default } from './MessagebarDefault.stories'; | ||
|
|
||
| export default { | ||
| title: 'Preview Components/Messagebar', | ||
| component: Messagebar, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: [descriptionMd, bestPracticesMd].join('\n'), | ||
| }, | ||
| }, | ||
| }, | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.