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(inputs): fix aria with shadow-dom #16329

Merged
merged 13 commits into from
Nov 16, 2018
12 changes: 7 additions & 5 deletions angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,16 @@ export declare interface Datetime extends StencilComponents<'IonDatetime'> {}
export class Datetime {
ionCancel: EventEmitter<CustomEvent>;
ionChange: EventEmitter<CustomEvent>;
ionFocus: EventEmitter<CustomEvent>;
ionBlur: EventEmitter<CustomEvent>;
ionStyle: EventEmitter<CustomEvent>;

constructor(c: ChangeDetectorRef, r: ElementRef) {
c.detach();
const el = r.nativeElement;
proxyMethods(this, el, ['open']);
proxyInputs(this, el, ['mode', 'name', 'disabled', 'min', 'max', 'displayFormat', 'pickerFormat', 'cancelText', 'doneText', 'yearValues', 'monthValues', 'dayValues', 'hourValues', 'minuteValues', 'monthNames', 'monthShortNames', 'dayNames', 'dayShortNames', 'pickerOptions', 'placeholder', 'value']);
proxyOutputs(this, el, ['ionCancel', 'ionChange', 'ionStyle']);
proxyOutputs(this, el, ['ionCancel', 'ionChange', 'ionFocus', 'ionBlur', 'ionStyle']);
}
}

Expand Down Expand Up @@ -341,22 +343,22 @@ export class InfiniteScrollContent {
}

export declare interface Input extends StencilComponents<'IonInput'> {}
@Component({ selector: 'ion-input', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: '<ng-content></ng-content>', inputs: ['color', 'mode', 'accept', 'autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'debounce', 'disabled', 'inputmode', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'results', 'spellcheck', 'step', 'size', 'type', 'value'] })
@Component({ selector: 'ion-input', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: '<ng-content></ng-content>', inputs: ['color', 'mode', 'accept', 'autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'debounce', 'disabled', 'inputmode', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'spellcheck', 'step', 'size', 'type', 'value'] })
export class Input {
ionInput: EventEmitter<CustomEvent>;
ionChange: EventEmitter<CustomEvent>;
ionStyle: EventEmitter<CustomEvent>;
ionBlur: EventEmitter<CustomEvent>;
ionFocus: EventEmitter<CustomEvent>;
ionInputDidLoad: EventEmitter<CustomEvent>;
ionInputDidUnload: EventEmitter<CustomEvent>;
ionStyle: EventEmitter<CustomEvent>;

constructor(c: ChangeDetectorRef, r: ElementRef) {
c.detach();
const el = r.nativeElement;
proxyMethods(this, el, ['setFocus']);
proxyInputs(this, el, ['color', 'mode', 'accept', 'autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'debounce', 'disabled', 'inputmode', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'results', 'spellcheck', 'step', 'size', 'type', 'value']);
proxyOutputs(this, el, ['ionInput', 'ionChange', 'ionStyle', 'ionBlur', 'ionFocus', 'ionInputDidLoad', 'ionInputDidUnload']);
proxyInputs(this, el, ['color', 'mode', 'accept', 'autocapitalize', 'autocomplete', 'autocorrect', 'autofocus', 'clearInput', 'clearOnEdit', 'debounce', 'disabled', 'inputmode', 'max', 'maxlength', 'min', 'minlength', 'multiple', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'spellcheck', 'step', 'size', 'type', 'value']);
proxyOutputs(this, el, ['ionInput', 'ionChange', 'ionBlur', 'ionFocus', 'ionInputDidLoad', 'ionInputDidUnload', 'ionStyle']);
}
}

Expand Down
18 changes: 9 additions & 9 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,10 @@ export namespace Components {
*/
'name'?: string;
/**
* Emitted when the datetime loses focus.
*/
'onIonBlur'?: (event: CustomEvent<void>) => void;
/**
* Emitted when the datetime selection was cancelled.
*/
'onIonCancel'?: (event: CustomEvent<void>) => void;
Expand All @@ -1296,6 +1300,10 @@ export namespace Components {
*/
'onIonChange'?: (event: CustomEvent<InputChangeEvent>) => void;
/**
* Emitted when the datetime has focus.
*/
'onIonFocus'?: (event: CustomEvent<void>) => void;
/**
* Emitted when the styles change.
*/
'onIonStyle'?: (event: CustomEvent<StyleEvent>) => void;
Expand Down Expand Up @@ -1696,10 +1704,6 @@ export namespace Components {
*/
'required': boolean;
/**
* This is a nonstandard attribute supported by Safari that only applies when the type is `"search"`. Its value should be a nonnegative decimal integer.
*/
'results'?: number;
/**
* Sets focus on the specified `ion-input`. Use this method instead of the global `input.focus()`.
*/
'setFocus': () => void;
Expand Down Expand Up @@ -1842,10 +1846,6 @@ export namespace Components {
*/
'required'?: boolean;
/**
* This is a nonstandard attribute supported by Safari that only applies when the type is `"search"`. Its value should be a nonnegative decimal integer.
*/
'results'?: number;
/**
* The initial size of the control. This value is in pixels unless the value of the type attribute is `"text"` or `"password"`, in which case it is an integer number of characters. This attribute applies only when the `type` attribute is set to `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored.
*/
'size'?: number;
Expand Down Expand Up @@ -4052,7 +4052,7 @@ export namespace Components {
/**
* Opens the select overlay, it could be an alert, action-sheet or popover, based in `ion-select` settings.
*/
'open': (ev?: UIEvent | undefined) => Promise<OverlaySelect>;
'open': (ev?: UIEvent | undefined) => Promise<HTMLIonActionSheetElement | HTMLIonAlertElement | HTMLIonPopoverElement | undefined>;
/**
* The text to display when the select is empty.
*/
Expand Down
4 changes: 2 additions & 2 deletions core/src/components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class Alert implements ComponentInterface, OverlayInterface {
<button
type="button"
onClick={() => this.cbClick(i)}
aria-checked={i.checked ? 'true' : null}
aria-checked={`${i.checked}`}
id={i.id}
disabled={i.disabled}
tabIndex={0}
Expand Down Expand Up @@ -356,7 +356,7 @@ export class Alert implements ComponentInterface, OverlayInterface {
<button
type="button"
onClick={() => this.rbClick(i)}
aria-checked={i.checked ? 'true' : null}
aria-checked={`${i.checked}`}
disabled={i.disabled}
id={i.id}
tabIndex={0}
Expand Down
1 change: 1 addition & 0 deletions core/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class Button implements ComponentInterface {

return {
'ion-activatable': true,
'aria-disabled': this.disabled ? 'true' : null,
class: {
...createColorClasses(color),
[buttonType]: true,
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/checkbox/checkbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
--checkmark-color: #{current-color(contrast)};
}

input {
button {
@include input-cover();
}

Expand Down
34 changes: 19 additions & 15 deletions core/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, ComponentInterface, Element, Event, EventEmitter, Prop, State, Watch } from '@stencil/core';

import { CheckedInputChangeEvent, Color, Mode, StyleEvent } from '../../interface';
import { renderHiddenInput } from '../../utils/helpers';
import { findItemLabel, renderHiddenInput } from '../../utils/helpers';
import { createColorClasses, hostContext } from '../../utils/theme';

@Component({
Expand All @@ -15,7 +15,6 @@ import { createColorClasses, hostContext } from '../../utils/theme';
export class Checkbox implements ComponentInterface {

private inputId = `ion-cb-${checkboxIds++}`;
private labelId = `${this.inputId}-lbl`;

@Element() el!: HTMLElement;

Expand Down Expand Up @@ -74,6 +73,7 @@ export class Checkbox implements ComponentInterface {

/**
* Emitted when the styles change.
* @internal
*/
@Event() ionStyle!: EventEmitter<StyleEvent>;

Expand All @@ -98,7 +98,7 @@ export class Checkbox implements ComponentInterface {
});
}

private onChange = () => {
private onClick = () => {
this.checked = !this.checked;
}

Expand All @@ -116,7 +116,16 @@ export class Checkbox implements ComponentInterface {
}

hostData() {
const labelId = this.inputId + '-lbl';
const label = findItemLabel(this.el);
if (label) {
label.id = labelId;
}
return {
'role': 'checkbox',
'aria-disabled': this.disabled ? 'true' : null,
'aria-checked': `${this.checked}`,
'aria-labelledby': labelId,
class: {
...createColorClasses(this.color),
'in-item': hostContext('ion-item', this.el),
Expand All @@ -129,7 +138,7 @@ export class Checkbox implements ComponentInterface {
}

render() {
renderHiddenInput(this.el, this.name, this.value, this.disabled);
renderHiddenInput(true, this.el, this.name, (this.checked ? this.value : ''), this.disabled);

return [
<svg class="checkbox-icon" viewBox="0 0 24 24">
Expand All @@ -138,19 +147,14 @@ export class Checkbox implements ComponentInterface {
: <path d="M5.9,12.5l3.8,3.8l8.8-8.8"/>
}
</svg>,
<input
type="checkbox"
id={this.inputId}
aria-labelledby={this.labelId}
onChange={this.onChange}
<button
type="button"
onClick={this.onClick}
onKeyUp={this.onKeyUp}
onFocus={this.onFocus}
onBlur={this.onBlur}
onKeyUp={this.onKeyUp}
checked={this.checked}
name={this.name}
value={this.value}
disabled={this.disabled}
/>
>
</button>
];
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/components/checkbox/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Checkboxes allow the selection of multiple options from a set of options. They a
| `ionBlur` | Emitted when the toggle loses focus. | void |
| `ionChange` | Emitted when the checked property has changed. | CheckedInputChangeEvent |
| `ionFocus` | Emitted when the toggle has focus. | void |
| `ionStyle` | Emitted when the styles change. | StyleEvent |


## CSS Custom Properties
Expand Down
3 changes: 2 additions & 1 deletion core/src/components/datetime/datetime.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@

:host(.datetime-disabled) {
opacity: .3;
pointer-events: none;
}

.datetime-cover {
button {
@include input-cover();
}

Expand Down
Loading