-
Notifications
You must be signed in to change notification settings - Fork 385
feat(menu): add optional danger state for menu items #8131
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-ico | |
|
|
||
| ```ts file="MenuBasic.tsx" | ||
| ``` | ||
|
|
||
| ### With icons | ||
|
|
||
| ```ts file="MenuWithIcons.tsx" | ||
|
|
@@ -119,3 +118,8 @@ To render an initially drilled in menu, the `menuDrilledIn`, `drilldownPath`, an | |
|
|
||
| ```ts file="MenuWithViewMore.tsx" | ||
| ``` | ||
|
|
||
| ### Danger menu item | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this example up so it is the second one on the page. Typically we try and keep our example order aligned with the HTML examples when possible.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tlabaj oh, I made a comment in the core PR to move it after the "view more" and "loading" examples, since those seem like similar variations, but I missed that it wasn't made before merging. WDYT? patternfly/patternfly#5102 (review) |
||
|
|
||
| ```ts file="MenuDangerMenuItem.tsx" | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import React from 'react'; | ||
| import { Divider, Menu, MenuContent, MenuItem, MenuList } from '@patternfly/react-core'; | ||
|
|
||
| export const MenuDangerMenuItem: React.FunctionComponent = () => { | ||
| const [activeItem, setActiveItem] = React.useState(0); | ||
|
|
||
| const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, itemId: number | string | undefined) => { | ||
| const item = itemId as number; | ||
| // eslint-disable-next-line no-console | ||
| console.log(`clicked ${itemId}`); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made this log call for consistency with the other examples. |
||
| setActiveItem(item); | ||
| }; | ||
|
|
||
| return ( | ||
| <Menu activeItemId={activeItem} onSelect={onSelect}> | ||
| <MenuContent> | ||
| <MenuList> | ||
| <MenuItem itemId={0}>Action 1</MenuItem> | ||
| <MenuItem itemId={1}>Action 2</MenuItem> | ||
| <Divider component="li" /> | ||
| <MenuItem itemId={2} isDanger> | ||
| Delete | ||
| </MenuItem> | ||
| </MenuList> | ||
| </MenuContent> | ||
| </Menu> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically for these statuses, we include some sr-only text
patternfly-react/packages/react-core/src/components/Popover/Popover.tsx
Line 452 in 60f9853
We have the sr-only text in the core example. Should we add that? cc @thatblindgeye
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like an interesting scenario to me. I think it could really go either way, but it would bring into question whether the "danger"/"warning" variant of our Button component should have similar visually hidden text.
I don't believe I've seen visually hidden text like this used for "danger" menu items/buttons before, and it could possibly stray into being too verbose (especially the more visually hidden text there is on a page)... but at the same time, if we want to visually convey these menu items as "danger" items to users that are sighted, regardless if there's an additional step from a confirmation modal, it could make sense to convey that a menu item is a "danger" item to users of AT similarly.
Looking at Web-AIM's invisible content page in the "Examples" section, they have a note about:
Which this scenario could technically fit into that sort of criteria (a "danger" item is apparent visually via the text color, but not as such to users that are blind and navigating via SR).
It could possibly come down to whether the text of the "danger" menu item is enough to convey that it is a dangerous/destructive action (i.e. will these dangerous items always be as clear as "Delete"), or whether the additional context via color and/or visually hidden text is needed to help convey that dangerous/destruction nature (i.e. is the text color more to convey an item as dangerous/destructive, or more to just visually separate it from other menu items?).
I think I'd generally be okay with SR text being added, but it would probably lead to a broader convo regarding other components like Button that also have status/severity sort of visual styling.