-
Notifications
You must be signed in to change notification settings - Fork 665
ValidationSummary: add accessibility support #32234
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: 26_1
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 |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import eventsEngine from '@js/common/core/events/core/events_engine'; | ||
| import registerComponent from '@js/core/component_registrator'; | ||
| import type { dxElementWrapper } from '@js/core/renderer'; | ||
| import $ from '@js/core/renderer'; | ||
| // @ts-expect-error ts-error | ||
| import { grep } from '@js/core/utils/common'; | ||
| import { extend } from '@js/core/utils/extend'; | ||
|
|
@@ -12,6 +14,7 @@ import ValidationEngine from './m_validation_engine'; | |
| import type ValidationGroup from './m_validation_group'; | ||
|
|
||
| const VALIDATION_SUMMARY_CLASS = 'dx-validationsummary'; | ||
| const SCREEN_READER_ONLY_CLASS = 'dx-screen-reader-only'; | ||
| const ITEM_CLASS = `${VALIDATION_SUMMARY_CLASS}-item`; | ||
| const ITEM_DATA_KEY = `${VALIDATION_SUMMARY_CLASS}-item-data`; | ||
|
|
||
|
|
@@ -26,6 +29,10 @@ class ValidationSummary extends CollectionWidget<ValidationSummaryProperties> { | |
|
|
||
| validators?: any[]; | ||
|
|
||
| _$announceContainer?: dxElementWrapper; | ||
|
|
||
| _lastAnnouncedText?: string; | ||
|
|
||
| groupSubscription?: (params) => void; | ||
|
|
||
| _getDefaultOptions(): ValidationSummaryProperties { | ||
|
|
@@ -117,6 +124,43 @@ class ValidationSummary extends CollectionWidget<ValidationSummaryProperties> { | |
| }); | ||
|
|
||
| this.option('items', items); | ||
|
|
||
| this._announceOnGroupValidation(items); | ||
| } | ||
|
|
||
| _announceOnGroupValidation(items): void { | ||
|
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. Is it necessary to pass an extra argument to this function? We already have access to the current items value inside it. |
||
| if (!items?.length) { | ||
|
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. Kindly check all code blocks and make sure that all scenarios are covered by tests. Currently, I see only tests for basic scenarios. |
||
| this._lastAnnouncedText = ''; | ||
| this._removeAnnounceContainer(); | ||
| return; | ||
| } | ||
|
|
||
| const text = items.map((item) => item.text).join('. '); | ||
|
|
||
| if (text !== this._lastAnnouncedText) { | ||
| this._lastAnnouncedText = text; | ||
| this._announceText(text); | ||
| } | ||
| } | ||
|
|
||
| _removeAnnounceContainer(): void { | ||
| this._$announceContainer?.remove(); | ||
| this._$announceContainer = undefined; | ||
| } | ||
|
|
||
| _renderAnnounceContainer(): void { | ||
| this._removeAnnounceContainer(); | ||
|
|
||
| this._$announceContainer = $('<div>') | ||
| .addClass(SCREEN_READER_ONLY_CLASS) | ||
| .attr('role', 'alert') | ||
|
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. Maybe it’s better to use the setAria(...) utility function |
||
| .appendTo(this.element()); | ||
| } | ||
|
|
||
| _announceText(text: string): void { | ||
| this._renderAnnounceContainer(); | ||
|
|
||
| this._$announceContainer?.text(text); | ||
|
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. I don’t see any runtime processing. Is it not necessary? |
||
| } | ||
|
|
||
| _itemValidationHandler({ isValid, validator, brokenRules }): void { | ||
|
|
@@ -164,6 +208,7 @@ class ValidationSummary extends CollectionWidget<ValidationSummaryProperties> { | |
|
|
||
| _initMarkup(): void { | ||
| this.$element().addClass(VALIDATION_SUMMARY_CLASS); | ||
|
|
||
| super._initMarkup(); | ||
| } | ||
|
|
||
|
|
@@ -192,6 +237,7 @@ class ValidationSummary extends CollectionWidget<ValidationSummaryProperties> { | |
| } | ||
|
|
||
| _dispose(): void { | ||
| this._removeAnnounceContainer(); | ||
| super._dispose(); | ||
| this._unsubscribeGroup(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ export const CLASS = { | |
| workspaceBothScrollbar: 'dx-scheduler-work-space-both-scrollbar', | ||
|
|
||
| workSpace: 'dx-scheduler-work-space', | ||
| statusContainer: 'dx-scheduler-a11y-status-container ', | ||
| statusContainer: 'dx-screen-reader-only', | ||
|
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. Will a single 'dx-screen-reader-only' class be sufficient if there is more than one container on the page?? Kindly check all cases |
||
| }; | ||
|
|
||
| const ViewTypeClassesMap = { | ||
|
|
||
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.