-
Notifications
You must be signed in to change notification settings - Fork 371
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
Merged
tlabaj
merged 3 commits into
patternfly:main
from
gefgu:feat/menu-optional-danger-state
Oct 21, 2022
Merged
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions
28
packages/react-core/src/components/Menu/examples/MenuDangerMenuItem.tsx
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,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}`); | ||
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> | ||
); | ||
}; |
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.
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.