Skip to content
Merged
Changes from all 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
38 changes: 37 additions & 1 deletion docs/content/SelectMenu.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@ SelectMenu components get `COMMON` system props. Read our [System Props](/system
| :- | :- | :-: | :- |
| initialTab | String | | If using the `SelectMenu.Tabs` component, you can use this prop to change the tab shown on open. By default, the first tab will be used.

## SelectMenu.MenuContext
SelectMenu.MenuContext is a [context object](https://reactjs.org/docs/context.html#reactcreatecontext) that exposes some helpful state values to be used via [`React.useContext`](https://reactjs.org/docs/hooks-reference.html#usecontext) in consuming applications. SelectMenu.MenuContext can only be used in components that are already wrapped in a `SelectMenu` as `SelectMenu` contains the [context provider](https://reactjs.org/docs/context.html#contextprovider).

### Values available on MenuContext
| Name | Type | Description |
| :- | :- | :- |
| selectedTab | string | The currently selected tab |
| setSelectedTab | function | Used to update the currently selected tab state |
| open | boolean | State for open/closed status of the menu modal |
| setOpen | function | Used to update the `open` state |
| initialTab | string | Mostly used internally to pass down which tab should be set to open by default. To change this value use the `initialTab` prop on `SelectMenu`. |


### Example Usage
```jsx
import {SelectMenu, Button} from `@primer/components`
import React, {useContext} from 'react'

const MyMenu = () => {
<SelectMenu>
<MyButton as="summary" />
<SelectMenu.Modal>
content
</SelectMenu.Modal>
</SelectMenu>
}

// note that we can only use the context in components that are already wrapped by SelectMenu (and thus the Context.Provider)
const MyButton = () => {
const menuContext = useContext(SelectMenu.MenuContext);

return (
<Button as="summary">{menuContext.open ? 'Open' : 'Closed'}</Button>
)
}
```

## SelectMenu.Modal
Used to wrap the content in a `SelectMenu`.
Expand Down Expand Up @@ -284,4 +320,4 @@ Use a `SelectMenu.Header` to add a header to the top of the select menu content.
SelectMenu.Header components get `COMMON` system props. Read our [System Props](/system-props) doc page for a full list of available props.

### Component Props
SelectMenu.Header components do not get any additional props besides system props.
SelectMenu.Header components do not get any additional props besides system props.