-
Notifications
You must be signed in to change notification settings - Fork 616
DropdownMenu #1135
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
Merged
DropdownMenu #1135
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
2898c3c
chore: Merge branch 'overlay' into dropdownmenu
smockle ae7841e
chore: Merge branch 'main' into dropdownmenu
smockle f45dfdb
feat: Add DropdownMenu
smockle 98f948e
fix: Don’t hardcode a palette emoji in DropdownMenu; it’s typically n…
smockle bb8e06d
feat: Enable deselection; draw checks by selected items and empty spa…
smockle d9576c8
feat: Add DropdownButton; begin adding required roles and other attri…
smockle 7bce122
chore: Merge branch 'main' into dropdownmenu
smockle e3869a7
fix: Imported types, plus Storybook warnings, plus debug List-level c…
smockle b812e73
fix: Restore 'List'-level custom 'Item' rendering.
smockle 0cdaab2
chore: Merge branch 'main' into dropdownmenu
smockle 007ce3b
chore: Merge 'dropdown-with-zones' into 'dropdownmenu'
smockle 16751fb
fix: keep focus on anchor when dropdown menu opens
dgreif 0029c37
fix: Rename focus-related state and values to distinguish/dedupe from…
smockle 5edc447
chore: Run Prettier
smockle f7bd529
fix: Add 'onDismiss' to the dependency list for 'onAnchorKeyDown' to …
smockle fd369a3
fix: force render after overlay ref is set
dgreif 3ec6103
fix(dropdown): treat enter and space on item as an activation
dgreif ccecdd1
fix: only prevent default if item is activated
dgreif 4a545f9
docs: basic docs in dropdown menu
dgreif 6edab5a
docs: add `DropdownMenu` docs
dgreif 9b8e9fd
chore: add basic tests to DropdownMenu
VanAnderson e89cf1e
fix: add placeholder value to DropdownMenu
VanAnderson ff6e266
fix: fix linter by removing unused import
VanAnderson 275ef22
refactor: allow DropdownMenu state to be controlled by parent
dgreif a789c3f
docs: remove positioning form overlay docs
dgreif 9fd1e23
fix: typescript fixes
dgreif 8eb67b4
chore: delete isRefObject
VanAnderson 1904563
add selectedItem to docs
VanAnderson d3cc00d
remove random dash in docs
VanAnderson 718b99d
make DropdownMenu a controlled component in the docs
VanAnderson 6c0ea65
restore custom anchor for DropdownMenu in storybook story
VanAnderson ae943e4
fix: avoid signal monkey patch during gatsby server side render
dgreif 4fd91cf
docs: memoize dropdown menu items in example
dgreif 398a9d8
docs: useRenderForcingRef
dgreif d3d9b87
docs: fix renderItems typo
dgreif 1fa39d4
fix: Readable yet equivalent 'aria-selected'. Fix typo.
smockle 800a738
fix: Replace 'ChevronIcon' with 'TriangleDownIcon' per latest style g…
smockle 710123a
refactor: use ternary for conditional child component rendering
dgreif c64b970
test: update snapshot for DropdownMenu
dgreif 33863d8
fix: use custom theme provider
dgreif edf01d5
fix: export tweaks
dgreif 1e89b2a
Merge branch 'main' into dropdownmenu
dgreif 42e8658
fix: cleanup after merging master
dgreif 7e74ab1
refactor: `setSelectedItem` -> `onChange`
dgreif f8b0609
chore: add comment explaining lack of DropdownMenu type exports
dgreif 7440928
refactor: `includes` instead of `indexOf`
dgreif 77a2e38
docs: replace `setSelectedItem` with `onChange`
dgreif 848d2fd
refactor: default value for dependency arrays
dgreif 9735116
refactor: simplify event key checks
dgreif 04946b4
chore: remove display name for `DropdownButton`
dgreif 75f9ed5
refactor: optional chaining for item event handlers
dgreif 33c4374
refactor: `itemActivated` -> `handleSelection`
dgreif 8eabeee
refactor: remove `randomId` in favor of `uniqueId`
dgreif 9054617
perf: useCallback for renderItem
dgreif 029ffad
Merge branch 'main' into dropdownmenu
dgreif 20ebbe1
Merge branch 'main' into dropdownmenu
smockle 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
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,42 @@ | ||
--- | ||
title: DropdownMenu | ||
--- | ||
|
||
A `DropdownMenu` provides an anchor (button by default) that will open a floating menu of selectable items. The menu can be opened and navigated using keyboard or mouse. When an item is selected, the menu will close and the `onChange` callback will be called. If the default anchor button is used, the anchor contents will be updated with the selection. | ||
|
||
## Example | ||
|
||
```javascript live noinline | ||
function DemoComponent() { | ||
const items = React.useMemo(() => [{text: '🔵 Cyan', id: 5}, {text: '🔴 Magenta'}, {text: '🟡 Yellow'}], []) | ||
const [selectedItem, setSelectedItem] = React.useState() | ||
|
||
return ( | ||
<DropdownMenu | ||
renderAnchor={({children, 'aria-labelledby': ariaLabelledBy, ...anchorProps}) => ( | ||
<DropdownButton aria-labelledby={`favorite-color-label ${ariaLabelledBy}`} {...anchorProps}> | ||
{children} | ||
</DropdownButton> | ||
)} | ||
placeholder="🎨" | ||
items={items} | ||
selectedItem={selectedItem} | ||
onChange={setSelectedItem} | ||
/> | ||
) | ||
} | ||
|
||
render(<DemoComponent />) | ||
``` | ||
|
||
## Component props | ||
|
||
| Name | Type | Default | Description | | ||
| :--------------- | :-------------------------------------------- | :---------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| items | `ItemProps[]` | `undefined` | Required. A list of item objects to display in the menu | | ||
| selectedItem | `ItemInput` | `undefined` | An `ItemProps` item from the list of `items` which is currently selected. This item will receive a checkmark next to it in the menu. | | ||
| onChange? | (item?: ItemInput) => unknown | `undefined` | A callback which receives the selected item or `undefined` when an item is activated in the menu. If the activated item is the same as the current `selectedItem`, `undefined` will be passed. | | ||
| placeholder | `string` | `undefined` | Optional. A placeholder value to display when there is no current selection. | | ||
| renderAnchor | `(props: DropdownButtonProps) => JSX.Element` | `DropdownButton` | Optional. If defined, provided component will be used to render the menu anchor. Will receive the selected `Item` text as `children` prop when an item is activated. | | ||
| renderItem | `(props: ItemProps) => JSX.Element` | `ActionList.Item` | Optional. If defined, each item in `items` will be passed to this function, allowing for custom item rendering. | | ||
| groupMetadata | `GroupProps[]` | `undefined` | Optional. If defined, `DropdownMenu` will group `items` into `ActionList.Group`s separated by `ActionList.Divider` according to their `groupId` property. | |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import {TriangleDownIcon} from '@primer/octicons-react' | ||
import Button, {ButtonProps} from '../Button/Button' | ||
import StyledOcticon from '../StyledOcticon' | ||
|
||
export type DropdownButtonProps = ButtonProps | ||
|
||
export const DropdownButton = React.forwardRef<HTMLElement, React.PropsWithChildren<DropdownButtonProps>>( | ||
({children, ...props}: React.PropsWithChildren<DropdownButtonProps>, ref): JSX.Element => ( | ||
<Button ref={ref} {...props}> | ||
{children} | ||
<StyledOcticon icon={TriangleDownIcon} ml={1} /> | ||
</Button> | ||
) | ||
) |
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.