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

fix: Includes accessibility requirements for checkbox in core and platform #2989

Merged
merged 10 commits into from
Sep 1, 2020

Conversation

DeepakSap14
Copy link
Contributor

@DeepakSap14 DeepakSap14 commented Aug 5, 2020

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

  1. includes minimum aria-* tags required,
  2. tabIndex to put checkbox in tab order,
  3. title to put tooltip on checkbox,
  4. fix for Issue fix: Stop Label click event propagation for Checkbox #2866 by muting the event,
  5. fixing accessibility in core checkbox, platform checkbox and platform checkbox group.

Please check whether the PR fulfills the following requirements

Documentation checklist:

  • Documentation Examples
  • Stackblitz works for all examples

Copy link
Contributor

@sKudum sKudum left a 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

@netlify
Copy link

netlify bot commented Aug 5, 2020

Deploy preview for fundamental-ngx ready!

Built with commit 3aa5e23

https://deploy-preview-2989--fundamental-ngx.netlify.app

* take precedence so this may be omitted.
*/
@Input('aria-label')
ariaLabel = '';
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor

@sKudum sKudum left a 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;
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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;
Copy link
Member

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 = '';
Copy link
Member

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?

Copy link
Member

@KevinOkamoto KevinOkamoto left a 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()"
Copy link
Member

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';

Copy link
Contributor Author

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"
Copy link
Member

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.

Copy link
Contributor Author

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().

Copy link
Member

@KevinOkamoto KevinOkamoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@DeepakSap14 DeepakSap14 changed the title [WIP] fix: (platform) Includes accessibility requirements for checkbox fix: (platform) Includes accessibility requirements for checkbox Aug 18, 2020
@DeepakSap14 DeepakSap14 changed the title fix: (platform) Includes accessibility requirements for checkbox fix: Includes accessibility requirements for checkbox in core and platform Aug 20, 2020
@@ -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';
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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 = '';
Copy link
Member

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 = '';
Copy link
Member

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;
Copy link
Member

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

Copy link
Contributor Author

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;
Copy link
Member

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 ?

Copy link
Contributor Author

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

@salarenko salarenko added the core Core library specific issues label Aug 21, 2020
@DeepakSap14
Copy link
Contributor Author

waiting #3083 to be merged. Need to rebase this PR on top of #3083.
review comments has been addressed. once rebase is done, will ask for review.

@DeepakSap14
Copy link
Contributor Author

This can be reviewed now.

Copy link
Member

@mikerodonnell89 mikerodonnell89 left a 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

Platform Development automation moved this from In Review to Approved by Reviewer Sep 1, 2020
@DeepakSap14 DeepakSap14 merged commit b3f5ac2 into master Sep 1, 2020
@DeepakSap14 DeepakSap14 deleted the fix/checkboxA11y branch September 1, 2020 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core library specific issues platform platform
Projects
No open projects
Platform Development
  
Approved by Reviewer
Development

Successfully merging this pull request may close these issues.

fix: Stop Label click event propagation for Checkbox Accessibility implementation in checkbox
7 participants