Skip to content
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

Merge DropdownMenu2 into ActionMenu2 #1848

Merged
merged 17 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions docs/content/drafts/ActionMenu2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,44 @@ You can choose to have a different _anchor_ for the Menu dependending on the app
</ActionMenu>
```

### With Selection
siddharthkp marked this conversation as resolved.
Show resolved Hide resolved

Use `selectionVariant` on `ActionList` to create a menu with single or multiple selection.

```javascript live noinline drafts
const fieldTypes = [
{icon: TypographyIcon, name: 'Text'},
{icon: NumberIcon, name: 'Number'},
{icon: CalendarIcon, name: 'Date'},
{icon: SingleSelectIcon, name: 'Single select'},
{icon: IterationsIcon, name: 'Iteration'}
]

const Example = () => {
const [selectedIndex, setSelectedIndex] = React.useState(1)
const selectedType = fieldTypes[selectedIndex]

return (
<ActionMenu>
<ActionMenu.Button aria-label="Select field type" leadingIcon={selectedType.icon}>
{selectedType.name}
</ActionMenu.Button>
<ActionMenu.Overlay width="medium">
<ActionList selectionVariant="single">
{fieldTypes.map((type, index) => (
<ActionList.Item key={index} selected={index === selectedIndex} onSelect={() => setSelectedIndex(index)}>
<type.icon /> {type.name}
</ActionList.Item>
))}
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
)
}

render(<Example />)
```

### With External Anchor

To create an anchor outside of the menu, you need to switch to controlled mode for the menu and pass it as `anchorRef` to `ActionMenu`. Make sure you add `aria-expanded` and `aria-haspopup` to the external anchor:
Expand Down Expand Up @@ -241,12 +279,6 @@ render(
)
```

<Note variant="warning">

Use `ActionMenu` to choose an action from a list. If you’re looking for single or multiple selection, use [DropdownMenu](/DropdownMenu) or [SelectPanel](/SelectPanel) instead.

</Note>

## Props / API reference

### ActionMenu
Expand Down Expand Up @@ -305,6 +337,5 @@ Use `ActionMenu` to choose an action from a list. If you’re looking for single
## Related components

- [ActionList](/drafts/ActionList2)
- [DropdownMenu](/DropdownMenu)
- [SelectPanel](/SelectPanel)
- [Button](/drafts/Button2)
Loading