-
Notifications
You must be signed in to change notification settings - Fork 278
feat(ui5-list): inherit list item aria roles from accessibleRole #13463
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
Open
plamenivanov91
wants to merge
1
commit into
main
Choose a base branch
from
li-expose-accRole
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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 |
|---|---|---|
|
|
@@ -180,17 +180,23 @@ abstract class ListItem extends ListItemBase { | |
|
|
||
| /** | ||
| * Used to define the role of the list item. | ||
| * @private | ||
| * | ||
| * **Note:** If not set, the role is automatically inherited from the parent `ui5-list` based on its `accessible-role` property | ||
| * (e.g. `Menu` -> `MenuItem`, `Tree` -> `TreeItem`, `ListBox` -> `Option`). | ||
| * An explicitly set `accessible-role` on the list item takes precedence over the inherited role. | ||
| * @default "ListItem" | ||
| * @public | ||
| * @since 1.3.0 | ||
| * | ||
| */ | ||
| @property() | ||
| accessibleRole: `${ListItemAccessibleRole}` = "ListItem"; | ||
| accessibleRole?: `${ListItemAccessibleRole}`; | ||
|
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. Should the type be narrowed to exclude Group? Using |
||
|
|
||
| @property() | ||
| _forcedAccessibleRole?: string; | ||
|
|
||
| @property({ noAttribute: true }) | ||
| _inheritedAccessibleRole?: string; | ||
|
|
||
| @property() | ||
| _selectionMode: `${ListSelectionMode}` = "None"; | ||
|
|
||
|
|
@@ -436,7 +442,13 @@ abstract class ListItem extends ListItemBase { | |
| } | ||
|
|
||
| get listItemAccessibleRole() { | ||
| return (this._forcedAccessibleRole || this.accessibleRole.toLowerCase()) as AriaRole | undefined; | ||
| if (this._forcedAccessibleRole) { | ||
| return this._forcedAccessibleRole as AriaRole; | ||
| } | ||
| if (this.accessibleRole) { | ||
| return this.accessibleRole.toLowerCase() as AriaRole; | ||
| } | ||
| return (this._inheritedAccessibleRole || "listitem") as AriaRole; | ||
| } | ||
|
|
||
| get ariaSelectedText() { | ||
|
|
||
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,85 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
| <meta charset="utf-8"> | ||
| <title>ui5-list / ui5-li - accessible-role inheritance</title> | ||
| <script src="%VITE_BUNDLE_PATH%" type="module"></script> | ||
| <style> | ||
| body { | ||
| padding: 1rem 2rem; | ||
| font-family: var(--sapFontFamily); | ||
| } | ||
| section { | ||
| margin-bottom: 2rem; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
|
|
||
| <ui5-title level="H2">List accessible-role ? child role inheritance</ui5-title> | ||
| <br/> | ||
|
|
||
| <!-- 1. Default (no role set) --> | ||
| <section> | ||
| <ui5-title level="H4">Default: accessible-role="List" (default) ? children get role="listitem"</ui5-title> | ||
| <ui5-list id="listDefault" header-text="Default List"> | ||
| <ui5-li id="li-default-1">Item 1</ui5-li> | ||
| <ui5-li id="li-default-2">Item 2</ui5-li> | ||
| <ui5-li id="li-default-3">Item 3</ui5-li> | ||
| </ui5-list> | ||
| </section> | ||
|
|
||
| <!-- 2. Menu role --> | ||
| <section> | ||
| <ui5-title level="H4">accessible-role="Menu" ? children inherit role="menuitem"</ui5-title> | ||
| <ui5-list id="listMenu" accessible-role="Menu" header-text="Menu List"> | ||
| <ui5-li id="li-menu-1">Open</ui5-li> | ||
| <ui5-li id="li-menu-2">Save</ui5-li> | ||
| <ui5-li id="li-menu-3">Save As?</ui5-li> | ||
| <ui5-li id="li-menu-4">Close</ui5-li> | ||
| </ui5-list> | ||
| </section> | ||
|
|
||
| <!-- 3. ListBox role --> | ||
| <section> | ||
| <ui5-title level="H4">accessible-role="ListBox" ? children inherit role="option"</ui5-title> | ||
| <ui5-list id="listBox" accessible-role="ListBox" header-text="ListBox"> | ||
| <ui5-li id="li-listbox-1">Option A</ui5-li> | ||
| <ui5-li id="li-listbox-2">Option B</ui5-li> | ||
| <ui5-li id="li-listbox-3">Option C</ui5-li> | ||
| </ui5-list> | ||
| </section> | ||
|
|
||
| <!-- 4. Tree role --> | ||
| <section> | ||
| <ui5-title level="H4">accessible-role="Tree" ? children inherit role="treeitem"</ui5-title> | ||
| <ui5-list id="listTree" accessible-role="Tree" header-text="Tree List"> | ||
| <ui5-li id="li-tree-1">Node 1</ui5-li> | ||
| <ui5-li id="li-tree-2">Node 2</ui5-li> | ||
| <ui5-li id="li-tree-3">Node 3</ui5-li> | ||
| </ui5-list> | ||
| </section> | ||
|
|
||
| <!-- 5. Explicit accessible-role on ui5-li overrides inherited --> | ||
| <section> | ||
| <ui5-title level="H4">Explicit accessible-role on ui5-li overrides inherited role from ui5-list</ui5-title> | ||
| <ui5-list id="listMenuOverride" accessible-role="Menu" header-text="Menu with override"> | ||
| <ui5-li id="li-override-1">Inherits menuitem from list</ui5-li> | ||
| <ui5-li id="li-override-2" accessible-role="Option">Explicitly set to "option"</ui5-li> | ||
| <ui5-li id="li-override-3">Inherits menuitem from list</ui5-li> | ||
| </ui5-list> | ||
| </section> | ||
|
|
||
| <!-- 6. Standalone explicit accessible-role on ui5-li --> | ||
| <section> | ||
| <ui5-title level="H4">Explicit accessible-role="MenuItem" set directly on ui5-li (no list role)</ui5-title> | ||
| <ui5-list id="listStandalone" header-text="Standard list with explicit item role"> | ||
| <ui5-li id="li-standalone-1" accessible-role="MenuItem">Explicit menuitem</ui5-li> | ||
| <ui5-li id="li-standalone-2">Default listitem</ui5-li> | ||
| <ui5-li id="li-standalone-3">Default listitem</ui5-li> | ||
| </ui5-list> | ||
| </section> | ||
|
|
||
| </body> | ||
| </html> |
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
5 changes: 5 additions & 0 deletions
5
packages/website/docs/_samples/main/List/AccessibleRole/AccessibleRole.md
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,5 @@ | ||
| import html from '!!raw-loader!./sample.html'; | ||
| import js from '!!raw-loader!./main.js'; | ||
| import react from '!!raw-loader!./sample.tsx'; | ||
|
|
||
| <Editor html={html} js={js} react={react} /> |
7 changes: 7 additions & 0 deletions
7
packages/website/docs/_samples/main/List/AccessibleRole/main.js
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,7 @@ | ||
| import "@ui5/webcomponents/dist/List.js"; | ||
| import "@ui5/webcomponents/dist/ListItemStandard.js"; | ||
|
|
||
| import "@ui5/webcomponents-icons/dist/create.js"; | ||
| import "@ui5/webcomponents-icons/dist/save.js"; | ||
| import "@ui5/webcomponents-icons/dist/delete.js"; | ||
| import "@ui5/webcomponents-icons/dist/filter.js"; |
44 changes: 44 additions & 0 deletions
44
packages/website/docs/_samples/main/List/AccessibleRole/sample.html
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,44 @@ | ||
| <!-- playground-fold --> | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Sample</title> | ||
| </head> | ||
|
|
||
| <body style="background-color: var(--sapBackgroundColor)"> | ||
| <!-- playground-fold-end --> | ||
|
|
||
| <!-- Menu: list role="menu", items inherit role="menuitem" --> | ||
| <ui5-list accessible-role="Menu" header-text="Actions"> | ||
| <ui5-li icon="create">New Document</ui5-li> | ||
| <ui5-li icon="save">Save</ui5-li> | ||
| <ui5-li icon="delete">Delete</ui5-li> | ||
| </ui5-list> | ||
|
|
||
| <br> | ||
|
|
||
| <!-- ListBox: list role="listbox", items inherit role="option" --> | ||
| <ui5-list accessible-role="ListBox" header-text="Select a Country"> | ||
| <ui5-li>Argentina</ui5-li> | ||
| <ui5-li>Bulgaria</ui5-li> | ||
| <ui5-li>China</ui5-li> | ||
| </ui5-list> | ||
|
|
||
| <br> | ||
|
|
||
| <!-- Explicit accessible-role on ui5-li overrides the inherited role --> | ||
| <ui5-list accessible-role="Menu" header-text="Mixed Roles (override)"> | ||
| <ui5-li icon="create">Inherits menuitem</ui5-li> | ||
| <ui5-li icon="filter" accessible-role="None">Separator-like (role=none)</ui5-li> | ||
| <ui5-li icon="save">Inherits menuitem</ui5-li> | ||
| </ui5-list> | ||
|
|
||
| <!-- playground-fold --> | ||
| <script type="module" src="main.js"></script> | ||
| </body> | ||
|
|
||
| </html> | ||
| <!-- playground-fold-end --> |
45 changes: 45 additions & 0 deletions
45
packages/website/docs/_samples/main/List/AccessibleRole/sample.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,45 @@ | ||
| import createReactComponent from "@ui5/webcomponents-base/dist/createReactComponent.js"; | ||
| import ListClass from "@ui5/webcomponents/dist/List.js"; | ||
| import ListItemStandardClass from "@ui5/webcomponents/dist/ListItemStandard.js"; | ||
| import "@ui5/webcomponents-icons/dist/create.js"; | ||
| import "@ui5/webcomponents-icons/dist/save.js"; | ||
| import "@ui5/webcomponents-icons/dist/delete.js"; | ||
| import "@ui5/webcomponents-icons/dist/filter.js"; | ||
|
|
||
| const List = createReactComponent(ListClass); | ||
| const ListItemStandard = createReactComponent(ListItemStandardClass); | ||
|
|
||
| function App() { | ||
| return ( | ||
| <> | ||
| {/* Menu: list role="menu", items inherit role="menuitem" */} | ||
| <List accessibleRole="Menu" headerText="Actions"> | ||
| <ListItemStandard icon="create">New Document</ListItemStandard> | ||
| <ListItemStandard icon="save">Save</ListItemStandard> | ||
| <ListItemStandard icon="delete">Delete</ListItemStandard> | ||
| </List> | ||
|
|
||
| <br /> | ||
|
|
||
| {/* ListBox: list role="listbox", items inherit role="option" */} | ||
| <List accessibleRole="ListBox" headerText="Select a Country"> | ||
| <ListItemStandard>Argentina</ListItemStandard> | ||
| <ListItemStandard>Bulgaria</ListItemStandard> | ||
| <ListItemStandard>China</ListItemStandard> | ||
| </List> | ||
|
|
||
| <br /> | ||
|
|
||
| {/* Explicit accessible-role on ui5-li overrides the inherited role */} | ||
| <List accessibleRole="Menu" headerText="Mixed Roles (override)"> | ||
| <ListItemStandard icon="create">Inherits menuitem</ListItemStandard> | ||
| <ListItemStandard icon="filter" accessibleRole="None"> | ||
| Separator-like (role=none) | ||
| </ListItemStandard> | ||
| <ListItemStandard icon="save">Inherits menuitem</ListItemStandard> | ||
| </List> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default App; |
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.
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.
Should the
@default "ListItem"tag be updated to@default undefined?element.accessibleRole returns undefined when unset, even though the rendered role correctly falls back to "listitem" via the getter.