From 059a1330d9b00f3b0bb729862d7a2a27fd63fe3c Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 25 Oct 2017 15:07:22 -0500 Subject: [PATCH] fix(alert): alert radio, checkbox and aria fixes --- packages/core/src/components/alert/alert.tsx | 87 +++++++++++++------- 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/packages/core/src/components/alert/alert.tsx b/packages/core/src/components/alert/alert.tsx index 4f467359d0..0a1ef74e92 100644 --- a/packages/core/src/components/alert/alert.tsx +++ b/packages/core/src/components/alert/alert.tsx @@ -20,6 +20,7 @@ export class Alert { private animation: Animation; private activeId: string; private inputType: string; + private hdrId: string; @Element() private el: HTMLElement; @@ -38,7 +39,7 @@ export class Alert { @Prop() subTitle: string; @Prop() message: string; @Prop() buttons: AlertButton[] = []; - @Prop() inputs: AlertInput[] = []; + @Prop({ mutable: true }) inputs: AlertInput[] = []; @Prop() enableBackdropDismiss: boolean = true; @Prop() enterAnimation: AnimationBuilder; @@ -73,6 +74,12 @@ export class Alert { animation.onFinish((a: any) => { a.destroy(); + + const firstInput = this.el.querySelector('[tabindex]') as HTMLElement; + if (firstInput) { + firstInput.focus(); + } + this.ionViewDidEnter(); resolve(); }).play(); @@ -143,22 +150,31 @@ export class Alert { } } - rbClick(button: any) { - this.inputs.forEach(input => { - input.checked = (button === input); + rbClick(inputIndex: number) { + this.inputs = this.inputs.map((input, index) => { + input.checked = (inputIndex === index); + return input; }); - this.activeId = button.id; - if (button.handler) { - button.handler(button); + const rbButton = this.inputs[inputIndex]; + this.activeId = rbButton.id; + + if (rbButton.handler) { + rbButton.handler(rbButton); } } - cbClick(button: any) { - button.checked = !button.checked; + cbClick(inputIndex: number) { + this.inputs = this.inputs.map((input, index) => { + if (inputIndex === index) { + input.checked = !input.checked; + } + return input; + }); - if (button.handler) { - button.handler(button); + const cbButton = this.inputs[inputIndex]; + if (cbButton.handler) { + cbButton.handler(cbButton); } } @@ -233,8 +249,8 @@ export class Alert { return (
- { inputs.map(i => ( -