Menu
Menu
An arrow-key navigable Menu
which consists of MenuItems
. A Menu
can be employed to produce its common variants, including dropdown menus, select menus, and others. Menus
are keyboard navigable with both tab and arrow keys.
MenuItem
A MenuItem
is its own distinct component that is used by any kind of menu overlays i.e. dropdown menu and navigation menu.
Any Paragon component or export may be added to the code example.
() => {return (<Menu><MenuItem> A Menu Item</MenuItem><MenuItem iconBefore={Check}>A Menu Item With an Icon Before</MenuItem><MenuItem iconAfter={Check}>A Menu Item With an Icon After </MenuItem><MenuItem disabled>A Disabled Menu Item</MenuItem><MenuItem as={Hyperlink} destination="https://en.wikipedia.org/wiki/Hyperlink">A Link Menu Item</MenuItem><MenuItem as={Button} variant="tertiary" size="inline">A Button Menu Item</MenuItem><MenuItem as={Form.Checkbox}>A Checkbox Menu Item</MenuItem></Menu>);}
With Form
A Menu
can include things like forms.
Any Paragon component or export may be added to the code example.
() => {return (<Form.Group><Form.CheckboxSetname="color-two"onChange={(e) => console.log(e.target.value)}defaultValue={['green']}><Form.Label>Which Color?</Form.Label><Menu><MenuItem as={Form.Checkbox} value="red">Red</MenuItem><MenuItem as={Form.Checkbox} value="blue">Blue</MenuItem><MenuItem as={Form.Checkbox} value="green">Green</MenuItem><MenuItem as={Form.Checkbox} value="yellow">Yellow</MenuItem></Menu></Form.CheckboxSet></Form.Group>);}
With Modal
A Menu
can be implemented to appear inside a modalpopup
for a wide variety of use cases. The Modal
brings focus to the first menu element upon the click of the trigger, and can be escaped on click away or key press.
Any Paragon component or export may be added to the code example.
() => {const [isOpen, open, close] = useToggle(false);const [target, setTarget] = React.useState(null);const [selected, setSelected] = useState('...');return (<><Badge variant="secondary">I like {selected}</Badge><Button ref={setTarget} variant="primary" size="inline" onClick={open}>Click Me To Pick:</Button><ModalPopup positionRef={target} isOpen={isOpen} onClose={close} style={{width: 500, height: 50}}><div className="bg-white"><Menu><MenuItem as={Button} variant="tertiary" size="inline" onClick= {()=>setSelected('Beans')}>Beans</MenuItem><MenuItem as={Button} variant="tertiary" size="inline" onClick= {()=>setSelected('Greens')}>Greens</MenuItem><MenuItem as={Button} variant="tertiary" size="inline" onClick= {()=>setSelected('Tomatoes')}>Tomatoes</MenuItem><MenuItem as={Button} variant="tertiary" size="inline" onClick= {()=>setSelected('Potatoes')}>Potatoes</MenuItem></Menu></div></ModalPopup></>)}
Theme Variables (SCSS)#
$menu-box-shadow: $box-shadow !default;$menu-border-radius: .25em !default;$menu-bg: $white !default;$menu-max-height: 16.813rem !default;$menu-item-height: 3rem !default;$menu-item-width: 19rem !default;$menu-item-width-xs: 13.438rem !default;$menu-item-color: $body-color !default;$menu-item-bg: transparent !default;$menu-item-border-color: $menu-item-bg !default;$menu-item-border-width: $btn-border-width !default;$menu-item-hover-border: $menu-item-bg !default;$menu-item-padding-x: $btn-padding-x !default;$menu-item-padding-y: $btn-padding-y !default;$menu-item-hover-color: $btn-tertiary-color !default;$menu-item-hover-border-color: $menu-item-bg !default;$menu-item-hover-bg: $btn-tertiary-hover-bg !default;$menu-item-icon-margin-left: .25em !default;$menu-item-icon-margin-right: $menu-item-icon-margin-left !default;$menu-item-focus-bg: $btn-tertiary-active-bg !default;$menu-item-border: $menu-item-border-width solid $menu-item-border-color !default;$menu-select-btn-link-color: $primary-500 !default;$menu-select-btn-link-text-decoration-line: underline !default;$menu-select-btn-link-text-decoration-thickness: .125rem !default;
Props API#
- className
string
Specifies class name to append to the base element
- arrowKeyNavigationSelector
string
Default'a:not(:disabled),button:not(:disabled),input:not(:disabled)'Specifies the CSS selector string that indicates to which elements the user can navigate using the arrow keys
- as
elementType
Default'div'Specifies the base element
- children
node
DefaultnullSpecifies the content of the menu
- defaultSelected
bool
DefaultfalseSpecifies that this
MenuItem
is selected inside theSelectMenu
- className
string
Specifies class name to append to the base element
- children
node
DefaultnullSpecifies the content of the
MenuItem
- as
elementType
Default'button'Specifies the base element
- iconBefore
element
|func
Specifies the jsx before the content of the
MenuItem
- iconAfter
element
|func
Specifies the jsx after the content of the
MenuItem
Usage Insights#
Menu
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-learner-portal-enterprise | 20.36.0 | 1 | |
prospectus | 20.32.3 | 1 |
MenuItem
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-learning | 20.28.4 | 1 | |
prospectus | 20.32.3 | 1 |