Skip to content
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

feat(ui5-button): implement accText property #1439

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/main/src/Button.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
tabindex={{tabIndexValue}}
aria-expanded="{{accInfo.ariaExpanded}}"
aria-controls="{{accInfo.ariaControls}}"
aria-labelledby="{{ariaLabelledBy}}"
title="{{accInfo.title}}"
part="button"
>
Expand All @@ -32,8 +33,12 @@
</bdi>
</span>

{{#if accText}}
<span id="{{_id}}-accText" class="ui5-hidden-text">{{accText}}</span>
{{/if}}

{{#if hasButtonType}}
<span class="ui5-hidden-text">{{buttonTypeText}}</span>
<span id="{{_id}}-button-type-text" class="ui5-hidden-text">{{buttonTypeText}}</span>
{{/if}}
</button>

Expand Down
27 changes: 26 additions & 1 deletion packages/main/src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ const metadata = {
type: Boolean,
},

/**
* Defines the aria-label attribute.
* @type {String}
* @defaultvalue ""
* @since 1.0.0-rc.7
* @public
*/
accText: {
type: String,
defaultValue: undefined,
},

/**
* Defines if a content has been added to the default slot
* @private
Expand Down Expand Up @@ -234,7 +246,6 @@ class Button extends UI5Element {

constructor() {
super();

this._deactivate = () => {
if (activeButton) {
activeButton.active = false;
Expand Down Expand Up @@ -303,6 +314,20 @@ class Button extends UI5Element {
return getRTL() ? "rtl" : undefined;
}

get ariaLabelledBy() {
let result = "";

if (this.buttonTypeText) {
result += `${this._id}-button-type-text`;
}

if (this.accText) {
result += ` ${this._id}-accText`;
}

return result;
}

get hasButtonType() {
return this.design !== ButtonDesign.Default && this.design !== ButtonDesign.Transparent;
}
Expand Down
7 changes: 4 additions & 3 deletions packages/main/test/pages/Button.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@
<br/>
<br/>

<ui5-button icon="employee">Action Bar Button</ui5-button>
<ui5-button icon="download"></ui5-button>
<ui5-button icon="download"></ui5-button>
<ui5-button icon="employee" acc-text="No action">Action Bar Button</ui5-button>
<ui5-button icon="download" design="Positive"></ui5-button>
<ui5-button icon="download" acc-text="Download single file"></ui5-button>
<ui5-button icon="download" design="Positive" acc-text="Download single file"></ui5-button>

<br />
<br />
Expand Down