-
Notifications
You must be signed in to change notification settings - Fork 125
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
fix: Includes accessibility requirements for checkbox in core and platform #2989
Conversation
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 update the pr details
Deploy preview for fundamental-ngx ready! Built with commit 3aa5e23 |
* take precedence so this may be omitted. | ||
*/ | ||
@Input('aria-label') | ||
ariaLabel = ''; |
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.
aria-label, aria-labelled by,aria-disabled is widely used along most of the components, Won't it help to have them in base class
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.
@fkolar @KevinOkamoto , what do you suggest.
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.
I don't think an input is necessary, on core, application developer can simply use , so maybe the same thing here?
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.
tried without Input aria-label by passing aria-label/attr.aria-label to fdp-checkbox, but it does not work.
Need to paas aria-label to native html element, so the screen reader can work correctly.
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.
I agree we probably should put ariaLabel
, ariaLabelledBy
, etc. in the BaseInput class. However, I think we should do that in a separate PR. This will effect a lot of components, and I don't think it's appropriate to add to the file changes in this PR.
Let's create a GitHub issue for the ariaLabel
, etc. in BaseInput, and leave this code the way it is.
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.
I was about to ask dont we have these on BaseInput?
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.
@mikerodonnell89 you need that in core as you have wrapping component
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.
Ok that makes sense... needs to be on the input element specifically
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.
If we had few test scripts to. check accessibility that will add on.
@@ -235,6 +282,11 @@ export class CheckboxComponent implements ControlValueAccessor { | |||
return event.keyCode === 32; | |||
} | |||
|
|||
/** @hidden Determines event source based on key code */ | |||
private _isEnterKeyEvent(event: KeyboardEvent): boolean { | |||
return event.keyCode === 13; |
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.
Hardcoding hinders flexibility and adaptability for future changes. We should try to avoid it as much. as possible.
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.
yes, can use CDK keycodes instead
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.
it is core/checkbox, if you see at line 282. they have used event.keycode, so i kept in same format. if core team suggest the same then i will change it.
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.
you should use KeyUtil from the core library
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.
Done
c1372c4
to
2be2f88
Compare
@@ -235,6 +282,11 @@ export class CheckboxComponent implements ControlValueAccessor { | |||
return event.keyCode === 32; | |||
} | |||
|
|||
/** @hidden Determines event source based on key code */ | |||
private _isEnterKeyEvent(event: KeyboardEvent): boolean { | |||
return event.keyCode === 13; |
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.
you should use KeyUtil from the core library
* take precedence so this may be omitted. | ||
*/ | ||
@Input('aria-label') | ||
ariaLabel = ''; |
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.
I don't think an input is necessary, on core, application developer can simply use , so maybe the same thing here?
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.
Try to avoid property binding to functions and getters, as Angular will inefficiently call these after every change detection cycle. See https://angular.io/guide/interpolation#quick-execution
[attr.tabIndex]="tabIndex" | ||
[attr.aria-label]="ariaLabel || null" | ||
[attr.aria-labelledby]="ariaLabelledby" | ||
[attr.aria-checked]="_getAriaChecked()" |
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.
Instead of using the function call _getAriaChecked()
here, you should create a component property here, ariaChecked
and then update it's value in the nextValue()
method.
public ariaChecked: 'true' | 'false' | 'mixed';
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.
Done
[attr.aria-checked]="_getAriaChecked()" | ||
[attr.aria-describedby]="ariaDescribedby" | ||
[attr.aria-disabled]="ariaDisabled" | ||
[attr.title]="title" | ||
[class.fd-checkbox--compact]="compact" | ||
[ngClass]="state ? 'is-' + state : ''" | ||
[ngModel]="isChecked" |
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.
I see that isChecked
is a getter method. You should change it to a boolean property, and update it in the nextValue()
method ... do the same as _getAriaChecked()
above.
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.
changing isChecked will introduce breaking change. I have made changes for _getAriaChecked().
2be2f88
to
109d7ea
Compare
2880b0f
to
5b7b222
Compare
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.
Looks good.
b745ac8
to
8ac74da
Compare
@@ -11,7 +11,7 @@ import { | |||
} from '@angular/core'; | |||
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | |||
import { FdCheckboxValues } from './fd-checkbox-values.interface'; | |||
import { compareObjects } from '../../utils/public_api'; | |||
import { compareObjects, KeyUtil } from '../../utils/public_api'; |
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.
Dont use public_api for imports, referene these files.
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.
Done
* Includes the checkbox in the page tab sequence. | ||
*/ | ||
@Input() | ||
tabIndex = 0; |
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.
Let's switch this to @Attribute decorator, as tab index will have always constant value.
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.
using @Attribute in constructor now.
Done
* take precedence so this may be omitted. | ||
*/ | ||
@Input('aria-label') | ||
ariaLabel = ''; |
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.
I was about to ask dont we have these on BaseInput?
* take precedence so this may be omitted. | ||
*/ | ||
@Input('aria-label') | ||
ariaLabel = ''; |
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.
@mikerodonnell89 you need that in core as you have wrapping component
* Includes the checkbox in the page tab sequence. | ||
*/ | ||
@Input() | ||
tabIndex: string; |
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.
the same as in core
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.
Done
* CBG label for accessibility | ||
*/ | ||
@Input() | ||
ariaLabel: string; |
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.
Let's move this up. do we have some usecase aribaLabels also for component inheriting BaseComponent ?
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.
Moved these to base class created for all components.
Components other than form components will also need these aria-* tags for accessibility.
Done
8ac74da
to
31e736c
Compare
31e736c
to
3aa5e23
Compare
This can be reviewed now. |
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.
This looks good to me now, wondering if we should have an example for core as well or if the API docs should be enough
Please provide a link to the associated issue.
#2602
#2866
Please provide a brief summary of this pull request.
This PR provides checkbox accessibility requirements
Please check whether the PR fulfills the following requirements
https://github.com/SAP/fundamental-ngx/blob/master/CONTRIBUTING.md
https://github.com/SAP/fundamental-ngx/wiki/PR-Review-Checklist
Documentation checklist: