Repository navigation
docs(react-tree): document controlled action menus #37190
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
Open
Paul Mardling (PaulGMardling)
wants to merge
8
commits into
microsoft:master
Choose a base branch
from
PaulGMardling:docs/controlled-treeitem-menu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5697f61
docs(react-tree): document controlled action menus
PaulGMardling aaaea6c
docs(react-tree): restore focus from controlled action menus
PaulGMardling 1878fc3
docs(react-tree): establish pointer menu focus targets
PaulGMardling 9697144
docs(react-tree): preserve action menu toggle dismissal
PaulGMardling 7ce0cb1
Merge branch 'master' into docs/controlled-treeitem-menu
PaulGMardling 8026220
Merge branch 'master' into docs/controlled-treeitem-menu
PaulGMardling e9dd869
docs(react-tree): streamline controlled actions guidance
PaulGMardling f379ed4
Merge branch 'master' into docs/controlled-treeitem-menu
PaulGMardling 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
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
80 changes: 80 additions & 0 deletions
80
packages/react-components/react-tree/stories/src/Tree/TreeActionsControlled.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,80 @@ | ||
| import * as React from 'react'; | ||
| import type { JSXElement } from '@fluentui/react-components'; | ||
| import { | ||
| Button, | ||
| Menu, | ||
| MenuItem, | ||
| MenuList, | ||
| MenuPopover, | ||
| MenuTrigger, | ||
| Tree, | ||
| TreeItem, | ||
| TreeItemLayout, | ||
| } from '@fluentui/react-components'; | ||
| import { MoreHorizontal20Regular } from '@fluentui/react-icons'; | ||
|
|
||
| const ItemWithControlledMenu = ({ children }: { children: string }): JSXElement => { | ||
| const [open, setOpen] = React.useState(false); | ||
|
|
||
| return ( | ||
| <TreeItem itemType="leaf" aria-description="has actions"> | ||
| <TreeItemLayout | ||
| actions={{ | ||
| onVisibilityChange: (_, data) => { | ||
| if (!data.visible) { | ||
| setOpen(false); | ||
| } | ||
| }, | ||
| children: ( | ||
| <Menu open={open} onOpenChange={(_, data) => setOpen(data.open)}> | ||
| <MenuTrigger disableButtonEnhancement> | ||
| <Button | ||
| aria-label={`More options for ${children}`} | ||
| appearance="subtle" | ||
| icon={<MoreHorizontal20Regular />} | ||
| /> | ||
| </MenuTrigger> | ||
| <MenuPopover> | ||
| <MenuList> | ||
| <MenuItem>Open</MenuItem> | ||
| <MenuItem>Rename</MenuItem> | ||
| </MenuList> | ||
| </MenuPopover> | ||
| </Menu> | ||
| ), | ||
| }} | ||
| > | ||
| {children} | ||
| </TreeItemLayout> | ||
| </TreeItem> | ||
| ); | ||
| }; | ||
|
|
||
| export const ActionsControlled = (): JSXElement => ( | ||
| <Tree aria-label="Controlled action menus"> | ||
| <ItemWithControlledMenu>item 1</ItemWithControlledMenu> | ||
| <ItemWithControlledMenu>item 2</ItemWithControlledMenu> | ||
| </Tree> | ||
| ); | ||
|
|
||
| ActionsControlled.parameters = { | ||
| docs: { | ||
| description: { | ||
| story: ` | ||
| When a \`Menu\` in the \`actions\` slot is controlled, update its \`open\` state from both the menu's \`onOpenChange\` and the slot's \`onVisibilityChange\`. | ||
| Reset \`open\` to \`false\` when \`data.visible\` is \`false\`; leave it unchanged when the actions become visible. | ||
|
|
||
| Hidden actions are unmounted. Unmounting a menu does not reset controlled state stored in the tree item or notify \`onOpenChange\` that the menu has closed. | ||
| Without this reset, a menu whose state is still \`open\` remounts open when the actions become visible again. | ||
| Keep separate menu state for each tree item, outside the actions subtree. | ||
|
|
||
| Open an item's menu, move to the other item so the first item's actions disappear, then return. | ||
| The first item's actions should reappear with its menu closed, until you open it again. | ||
| The same reset applies when focus leaves the actions. | ||
|
|
||
| This example focuses on controlled state. As with the [Actions example](?path=/story/components-tree--actions), | ||
| provide a context menu with the same commands so actions are also available through the standard tree interaction pattern. | ||
| `, | ||
| }, | ||
| }, | ||
| }; | ||
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
Oops, something went wrong.
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.