Skip to content

Commit 188627e

Browse files
tsanislavgatevvladitasev
authored andcommitted
feat(ui5-datepicker): implement ACC support (#763)
1 parent 24b42fd commit 188627e

File tree

6 files changed

+73
-20
lines changed

6 files changed

+73
-20
lines changed

packages/main/src/DatePicker.hbs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
@ui5-change="{{_handleInputChange}}"
1515
@ui5-input="{{_handleInputLiveChange}}"
1616
data-sap-focus-ref
17+
._inputAccInfo ="{{accInfo}}"
1718
>
1819
{{#unless readonly}}
1920
<ui5-icon
2021
slot="icon"
2122
src="sap-icon://appointment-2"
2223
class="{{classes.icon}} ui5-datepicker-icon"
2324
tabindex="-1"
25+
accessible-name="{{openIconTitle}}"
26+
show-tooltip
2427
@click="{{togglePicker}}"
2528
></ui5-icon>
2629
{{/unless}}
@@ -46,6 +49,5 @@
4649
@ui5-selectedDatesChange="{{_calendar.onSelectedDatesChange}}"
4750
></ui5-calendar>
4851
</ui5-popover>
49-
5052
<slot name="formSupport"></slot>
5153
</div>

packages/main/src/DatePicker.js

+25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import CalendarDate from "@ui5/webcomponents-base/dist/dates/CalendarDate.js";
1313
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
1414
import { isShow } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js";
1515
import "./icons/appointment-2.js";
16+
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
17+
import { DATEPICKER_OPEN_ICON_TITLE, DATEPICKER_DATE_ACC_TEXT } from "./generated/i18n/i18n-defaults.js";
1618
import Icon from "./Icon.js";
1719
import Popover from "./Popover.js";
1820
import Calendar from "./Calendar.js";
@@ -285,6 +287,8 @@ class DatePicker extends UI5Element {
285287
onSelectedDatesChange: this._handleCalendarSelectedDatesChange.bind(this),
286288
selectedDates: [],
287289
};
290+
291+
this.i18nBundle = getI18nBundle("@ui5/webcomponents");
288292
}
289293

290294
onBeforeRendering() {
@@ -397,6 +401,26 @@ class DatePicker extends UI5Element {
397401
return this._oDateFormat;
398402
}
399403

404+
get accInfo() {
405+
return {
406+
"ariaDescribedBy": `${this._id}-date`,
407+
"ariaHasPopup": "true",
408+
"ariaAutoComplete": "none",
409+
"role": "combobox",
410+
"ariaOwns": `${this._id}-popover`,
411+
"ariaExpanded": this.isOpen(),
412+
"ariaDescription": this.dateAriaDescription,
413+
};
414+
}
415+
416+
get openIconTitle() {
417+
return this.i18nBundle.getText(DATEPICKER_OPEN_ICON_TITLE);
418+
}
419+
420+
get dateAriaDescription() {
421+
return this.i18nBundle.getText(DATEPICKER_DATE_ACC_TEXT);
422+
}
423+
400424
_getPopover() {
401425
return this.shadowRoot.querySelector("ui5-popover");
402426
}
@@ -544,6 +568,7 @@ class DatePicker extends UI5Element {
544568
Popover.define(),
545569
Calendar.define(),
546570
Input.define(),
571+
fetchI18nBundle("@ui5/webcomponents"),
547572
]);
548573

549574
super.define(...params);

packages/main/src/Input.hbs

+11-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
?required="{{required}}"
1717
.value="{{value}}"
1818
placeholder="{{inputPlaceholder}}"
19-
aria-invalid="{{ariaInvalid}}"
20-
aria-haspopup="{{ariaHasPopup}}"
21-
aria-describedby="{{ariaDescribedBy}}"
22-
aria-autocomplete="{{ariaAutoComplete}}"
19+
role="{{accInfo.input.role}}"
20+
aria-owns="{{accInfo.input.ariaOwns}}"
21+
aria-invalid="{{accInfo.input.ariaInvalid}}"
22+
aria-haspopup="{{accInfo.input.ariaHasPopup}}"
23+
aria-describedby="{{accInfo.input.ariaDescribedBy}}"
24+
aria-autocomplete="{{accInfo.input.ariaAutoComplete}}"
25+
aria-expanded="{{accInfo.input.ariaExpanded}}"
2326
@input="{{_handleInput}}"
2427
@change="{{_handleChange}}"
2528
data-sap-no-tab-ref
@@ -35,6 +38,10 @@
3538
<span id="{{_id}}-suggestionsText" class="ui5-hidden-text">{{suggestionsText}}</span>
3639
{{/if}}
3740

41+
{{#if accInfo.input.ariaDescribedBy}}
42+
<span id="{{accInfo.input.ariaDescribedBy}}" class="ui5-hidden-text">{{accInfo.input.ariaDescription}}</span>
43+
{{/if}}
44+
3845
{{#if hasValueState}}
3946
<span id="{{_id}}-descr" class="ui5-hidden-text">{{valueStateText}}</span>
4047
{{/if}}

packages/main/src/Input.js

+26-15
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ const metadata = {
220220
_popover: {
221221
type: Object,
222222
},
223+
224+
_inputAccInfo: {
225+
type: Object,
226+
},
227+
228+
_wrapperAccInfo: {
229+
type: Object,
230+
},
223231
},
224232
events: /** @lends sap.ui.webcomponents.main.Input.prototype */ {
225233
/**
@@ -568,28 +576,31 @@ class Input extends UI5Element {
568576
return this.type.toLowerCase();
569577
}
570578

571-
get ariaInvalid() {
572-
return this.valueState === ValueState.Error ? "true" : undefined;
573-
}
574-
575579
get suggestionsTextId() {
576580
return this.showSuggestions ? `${this._id}-suggestionsText` : "";
577-
}
581+
}
578582

579583
get valueStateTextId() {
580584
return this.hasValueState ? `${this._id}-descr` : "";
581585
}
582586

583-
get ariaDescribedBy() {
584-
return `${this.suggestionsTextId} ${this.valueStateTextId}`.trim();
585-
}
586-
587-
get ariaHasPopup() {
588-
return this.showSuggestions ? "true" : undefined;
589-
}
590-
591-
get ariaAutoComplete() {
592-
return this.showSuggestions ? "list" : undefined;
587+
get accInfo() {
588+
const ariaHasPopupDefault = this.showSuggestions ? "true" : undefined;
589+
const ariaAutoCompleteDefault = this.showSuggestions ? "list" : undefined;
590+
return {
591+
"wrapper": {
592+
},
593+
"input": {
594+
"ariaDescribedBy": this._inputAccInfo ? `${this.suggestionsTextId} ${this.valueStateTextId} ${this._inputAccInfo.ariaDescribedBy}`.trim() : `${this.suggestionsTextId} ${this.valueStateTextId}`.trim(),
595+
"ariaInvalid": this.valueState === ValueState.Error ? "true" : undefined,
596+
"ariaHasPopup": this._inputAccInfo ? this._inputAccInfo.ariaHasPopup : ariaHasPopupDefault,
597+
"ariaAutoComplete": this._inputAccInfo ? this._inputAccInfo.ariaAutoComplete : ariaAutoCompleteDefault,
598+
"role": this._inputAccInfo && this._inputAccInfo.role,
599+
"ariaOwns": this._inputAccInfo && this._inputAccInfo.ariaOwns,
600+
"ariaExpanded": this._inputAccInfo && this._inputAccInfo.ariaExpanded,
601+
"ariaDescription": this._inputAccInfo && this._inputAccInfo.ariaDescription,
602+
},
603+
};
593604
}
594605

595606
get hasValueState() {

packages/main/src/i18n/messagebundle.properties

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ BUTTON_ARIA_TYPE_REJECT=Negative Action
2525
#XACT: ARIA announcement for the emphasized button
2626
BUTTON_ARIA_TYPE_EMPHASIZED=Emphasized
2727

28+
#XACT: Date
29+
DATEPICKER_DATE_ACC_TEXT=Date
30+
31+
#XACT: DatePicker 'Open Picker' icon title
32+
DATEPICKER_OPEN_ICON_TITLE=Open Picker
33+
2834
#XTXT
2935
ICON_ACTION_SETTINGS=Settings
3036

packages/main/src/themes/DatePicker.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "./InvisibleTextStyles.css";
2+
13
:host(:not([hidden])) {
24
display: inline-block;
35
}

0 commit comments

Comments
 (0)