Skip to content

Commit e0f93fa

Browse files
authored
feat(ui5-date-picker): add ariaLabel and ariaLabelledby properties (#2126)
FIXES #2107
1 parent a58bf49 commit e0f93fa

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

packages/main/src/DatePicker.js

+27
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import DateFormat from "@ui5/webcomponents-localization/dist/DateFormat.js";
99
import CalendarType from "@ui5/webcomponents-base/dist/types/CalendarType.js";
1010
import CalendarDate from "@ui5/webcomponents-localization/dist/dates/CalendarDate.js";
1111
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
12+
import getEffectiveAriaLabelText from "@ui5/webcomponents-base/dist/util/getEffectiveAriaLabelText.js";
1213
import { isShow, isF4 } from "@ui5/webcomponents-base/dist/Keys.js";
1314
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
1415
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
@@ -217,6 +218,31 @@ const metadata = {
217218
type: Boolean,
218219
},
219220

221+
/**
222+
* Defines the aria-label attribute for the <code>ui5-date-picker</code>.
223+
*
224+
* @type {String}
225+
* @since 1.0.0-rc.9
226+
* @private
227+
* @defaultvalue ""
228+
*/
229+
ariaLabel: {
230+
type: String,
231+
},
232+
233+
/**
234+
* Receives id(or many ids) of the elements that label the <code>ui5-date-picker</code>.
235+
*
236+
* @type {String}
237+
* @defaultvalue ""
238+
* @private
239+
* @since 1.0.0-rc.9
240+
*/
241+
ariaLabelledby: {
242+
type: String,
243+
defaultValue: "",
244+
},
245+
220246
_isPickerOpen: {
221247
type: Boolean,
222248
noAttribute: true,
@@ -660,6 +686,7 @@ class DatePicker extends UI5Element {
660686
"ariaExpanded": this.isOpen(),
661687
"ariaDescription": this.dateAriaDescription,
662688
"ariaRequired": this.required,
689+
"ariaLabel": getEffectiveAriaLabelText(this),
663690
};
664691
}
665692

packages/main/src/Input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ class Input extends UI5Element {
10131013
"ariaOwns": this._inputAccInfo && this._inputAccInfo.ariaOwns,
10141014
"ariaExpanded": this._inputAccInfo && this._inputAccInfo.ariaExpanded,
10151015
"ariaDescription": this._inputAccInfo && this._inputAccInfo.ariaDescription,
1016-
"ariaLabel": getEffectiveAriaLabelText(this),
1016+
"ariaLabel": (this._inputAccInfo && this._inputAccInfo.ariaLabel) || getEffectiveAriaLabelText(this),
10171017
"ariaRequired": (this._inputAccInfo && this._inputAccInfo.ariaRequired) || this.required,
10181018
},
10191019
};

packages/main/test/pages/DatePicker.html

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ <h3>3 months range</h3>
112112
<h3>1 year range</h3>
113113
<ui5-date-picker id="minMax4" value="5 Feb 2021" min-date="5 Jan 2020" max-date="5 Jan 2021"></ui5-date-picker>
114114

115+
<section>
116+
<h3>Test ariaLabel and ariaLabelledBy</h3>
117+
<ui5-date-picker id="dpAriaLabel" aria-label="Hello World"></ui5-date-picker>
118+
<br>
119+
<ui5-label id="infoText">info text</ui5-label>
120+
<ui5-date-picker id="dpAriaLabelledBy" aria-labelledby="infoText"></ui5-date-picker>
121+
</section>
122+
115123
<section class="ui5-content-density-compact">
116124
<h3>DatePicker in Compact</h3>
117125
<div>

packages/main/test/pages/DatePicker_test_page.html

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ <h3>DatePicker with hide-week-numbers=true/false</h3>
7070
<ui5-date-picker id="dp18"></ui5-date-picker>
7171
<ui5-date-picker id="dp19" hide-week-numbers></ui5-date-picker>
7272

73+
<section>
74+
<h3>Test ariaLabel and ariaLabelledBy</h3>
75+
<ui5-date-picker id="dpAriaLabel" aria-label="Hello World"></ui5-date-picker>
76+
<br>
77+
<ui5-label id="infoText">info text</ui5-label>
78+
<ui5-date-picker id="dpAriaLabelledBy" aria-labelledby="infoText"></ui5-date-picker>
79+
</section>
80+
7381
<script>
7482
var originalGetDate = Date.prototype.getDate;
7583

packages/main/test/specs/DatePicker.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -717,4 +717,22 @@ describe("Date Picker Tests", () => {
717717
datepicker.innerInput.click();
718718
browser.keys(["Alt", "ArrowUp", "NULL"]);
719719
});
720+
721+
it("Tests aria-label", () => {
722+
const EXPECTED_ARIA_LABEL = "Hello World";
723+
724+
datepicker.id = "#dpAriaLabel";
725+
726+
assert.strictEqual(datepicker.innerInput.getAttribute("aria-label"), EXPECTED_ARIA_LABEL,
727+
"The aria-label is correct.")
728+
});
729+
730+
it("Tests aria-labelledby", () => {
731+
const EXPECTED_ARIA_LABEL = "info text";
732+
733+
datepicker.id = "#dpAriaLabelledBy";
734+
735+
assert.strictEqual(datepicker.innerInput.getAttribute("aria-label"), EXPECTED_ARIA_LABEL,
736+
"The aria-label is correct.")
737+
});
720738
});

0 commit comments

Comments
 (0)