-
Notifications
You must be signed in to change notification settings - Fork 273
feat(ui5-bar): allow role change #11134
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
base: main
Are you sure you want to change the base?
Changes from all 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 |
---|---|---|
|
@@ -5,12 +5,14 @@ import slot from "@ui5/webcomponents-base/dist/decorators/slot.js"; | |
import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js"; | ||
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js"; | ||
import type BarDesign from "./types/BarDesign.js"; | ||
import type BarAccessibleRole from "./types/BarAccessibleRole.js"; | ||
|
||
// Template | ||
import BarTemplate from "./BarTemplate.js"; | ||
|
||
// Styles | ||
import BarCss from "./generated/themes/Bar.css.js"; | ||
import type { AriaRole } from "@ui5/webcomponents-base/dist/types.js"; | ||
|
||
/** | ||
* @class | ||
|
@@ -65,6 +67,23 @@ class Bar extends UI5Element { | |
@property() | ||
design: `${BarDesign}` = "Header"; | ||
|
||
/** | ||
* Specifies the ARIA role applied to the component for accessibility purposes. | ||
* | ||
* **Note:** | ||
* | ||
* - Set accessibleRole to "toolbar" only when the component contains two or more active, interactive elements (such as buttons, links, or input fields) within the bar. | ||
* | ||
* - If there is only one or no active element, it is recommended to avoid using the toolbar role, as it implies a grouping of multiple interactive controls. | ||
* | ||
* @public | ||
* @default "Toolbar" | ||
* @since 2.10.0 | ||
* | ||
*/ | ||
@property() | ||
accessibleRole: `${BarAccessibleRole}` = "Toolbar"; | ||
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. We'll need to provide recommendations to the users on how to use this new property. 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 added additional documentation and example. But i've added a static example with just two bars explaining the both cases, because we don't provide dynamic change of the role, so such example wont be needed. |
||
|
||
/** | ||
* Defines the content at the start of the bar. | ||
* @public | ||
|
@@ -91,6 +110,7 @@ class Bar extends UI5Element { | |
get accInfo() { | ||
return { | ||
"label": this.design, | ||
"role": this.effectiveRole, | ||
}; | ||
} | ||
|
||
|
@@ -125,6 +145,10 @@ class Bar extends UI5Element { | |
ResizeHandler.deregister(child as HTMLElement, this._handleResizeBound); | ||
}, this); | ||
} | ||
|
||
get effectiveRole() { | ||
return this.accessibleRole.toLowerCase() === "toolbar" ? "toolbar" as AriaRole : undefined; | ||
} | ||
} | ||
|
||
Bar.define(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* ListItem accessible roles. | ||
* @public | ||
* @since 2.9.0 | ||
*/ | ||
enum BarAccessibleRole { | ||
|
||
/** | ||
* Represents the ARIA role "toolbar". | ||
* @public | ||
*/ | ||
Toolbar = "Toolbar", | ||
|
||
/** | ||
* Represents the ARIA role "none". | ||
* @public | ||
*/ | ||
None = "None" | ||
|
||
} | ||
|
||
export default BarAccessibleRole; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import Basic from "../../_samples/main/Bar/Basic/Basic.md"; | ||
import AccessibleRole from "../../_samples/main/Bar/AccessibleRole/AccessibleRole.md"; | ||
|
||
<%COMPONENT_OVERVIEW%> | ||
|
||
## Basic Sample | ||
<Basic /> | ||
|
||
<%COMPONENT_METADATA%> | ||
<%COMPONENT_METADATA%> | ||
|
||
## Bar with accessible role | ||
<AccessibleRole /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import html from '!!raw-loader!./sample.html'; | ||
import js from '!!raw-loader!./main.js'; | ||
|
||
<Editor html={html} js={js} /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import "@ui5/webcomponents/dist/Button.js"; | ||
import "@ui5/webcomponents/dist/Label.js"; | ||
import "@ui5/webcomponents/dist/Bar.js"; | ||
import "@ui5/webcomponents-icons/dist/home.js" | ||
import "@ui5/webcomponents-icons/dist/action-settings.js" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!-- 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 --> | ||
<ui5-label>Bar with two or more active items:</ui5-label> | ||
<ui5-bar design="Header" accessible-role="Toolbar"> | ||
<ui5-button icon="home" tooltip="Go home" design="Transparent" slot="startContent"></ui5-button> | ||
<ui5-label id="basic-label">Content</ui5-label> | ||
<ui5-button icon="action-settings" tooltip="Go to settings" slot="endContent"></ui5-button> | ||
</ui5-bar> | ||
<br> | ||
<ui5-label>Bar with less than two active items:</ui5-label> | ||
<ui5-bar design="Header"> | ||
<ui5-label id="basic-label">Storybook title</ui5-label> | ||
</ui5-bar> | ||
<!-- playground-fold --> | ||
<script type="module" src="main.js"></script> | ||
</body> | ||
</html> | ||
<!-- playground-fold-end --> | ||
|
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.
Please consider:
"toolbar"