Skip to content

Commit

Permalink
fix(a11y): only preventDefault for the onClick event (#22573)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandyscarney committed Nov 25, 2020
1 parent 5275332 commit 0786835
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
12 changes: 3 additions & 9 deletions core/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export class Checkbox implements ComponentInterface {
}
}

private onClick = () => {
private onClick = (ev: any) => {
ev.preventDefault();

this.setFocus();
this.checked = !this.checked;
this.indeterminate = false;
Expand Down Expand Up @@ -168,14 +170,6 @@ export class Checkbox implements ComponentInterface {
{labelText}
</label>
<input
onClick={(ev: Event) => {
{/**
* This is needed otherwise any click
* events set on `ion-item` are fired twice
*/}
ev.preventDefault();
ev.stopPropagation()
}}
type="checkbox"
aria-checked={`${checked}`}
disabled={disabled}
Expand Down
9 changes: 9 additions & 0 deletions core/src/components/checkbox/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
</ion-header>

<ion-content id="content">
<ion-item onClick="clickItem()">
<ion-label>Clickable Item</ion-label>
<ion-checkbox></ion-checkbox>
</ion-item>

<ion-item>
<ion-label>Default</ion-label>
<ion-checkbox checked></ion-checkbox>
Expand Down Expand Up @@ -126,6 +131,10 @@
console.log('Listen click: fired');
});
}

const clickItem = () => {
console.log('Item click: fired');
}
</script>

</body>
Expand Down
1 change: 0 additions & 1 deletion core/src/components/radio-group/radio-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export class RadioGroup implements ComponentInterface {

private onClick = (ev: Event) => {
ev.preventDefault();
ev.stopPropagation();

const selectedRadio = ev.target && (ev.target as HTMLElement).closest('ion-radio');
if (selectedRadio) {
Expand Down
3 changes: 0 additions & 3 deletions core/src/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,6 @@ export class Select implements ComponentInterface {
}

private onClick = (ev: UIEvent) => {
ev.preventDefault();
ev.stopPropagation();

this.setFocus();
this.open(ev);
}
Expand Down
1 change: 0 additions & 1 deletion core/src/components/toggle/toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export class Toggle implements ComponentInterface {

private onClick = (ev: Event) => {
ev.preventDefault();
ev.stopPropagation();

if (this.lastDrag + 300 < Date.now()) {
this.checked = !this.checked;
Expand Down

0 comments on commit 0786835

Please sign in to comment.