feat(action-sheet, alert): add id to AlertButton and ActionSheetButton (#18992)

resolves #22959

Co-authored-by: Liam DeBeasi <liamdebeasi@icloud.com>
This commit is contained in:
Devin Shoemaker
2021-06-29 13:17:19 -05:00
committed by GitHub
parent bdc1f2360d
commit 9e24a0b493
20 changed files with 46 additions and 2 deletions

View File

@ -21,5 +21,6 @@ export interface ActionSheetButton {
role?: 'cancel' | 'destructive' | 'selected' | string; role?: 'cancel' | 'destructive' | 'selected' | string;
icon?: string; icon?: string;
cssClass?: string | string[]; cssClass?: string | string[];
id?: string;
handler?: () => boolean | void | Promise<boolean | void>; handler?: () => boolean | void | Promise<boolean | void>;
} }

View File

@ -264,7 +264,7 @@ export class ActionSheet implements ComponentInterface, OverlayInterface {
</div> </div>
} }
{buttons.map(b => {buttons.map(b =>
<button type="button" class={buttonClass(b)} onClick={() => this.buttonClick(b)}> <button type="button" id={b.id} class={buttonClass(b)} onClick={() => this.buttonClick(b)}>
<span class="action-sheet-button-inner"> <span class="action-sheet-button-inner">
{b.icon && <ion-icon icon={b.icon} lazy={false} class="action-sheet-icon" />} {b.icon && <ion-icon icon={b.icon} lazy={false} class="action-sheet-icon" />}
{b.text} {b.text}

View File

@ -63,6 +63,7 @@ export class ActionSheetExample {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: 'trash', icon: 'trash',
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }
@ -120,6 +121,7 @@ async function presentActionSheet() {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: 'trash', icon: 'trash',
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }
@ -234,6 +236,7 @@ export const ActionSheetExample: React.FC = () => {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: trash, icon: trash,
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }
@ -291,6 +294,7 @@ export class ActionSheetExample {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: 'trash', icon: 'trash',
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }
@ -363,6 +367,7 @@ export default defineComponent({
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: trash, icon: trash,
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked') console.log('Delete clicked')
}, },

View File

@ -58,6 +58,10 @@
--ion-backdrop-opacity: 1; --ion-backdrop-opacity: 1;
} }
#delete-button {
color: #eb445a;
}
</style> </style>
<script> <script>
window.addEventListener('ionActionSheetDidDismiss', function (e) { console.log('didDismiss', e) }) window.addEventListener('ionActionSheetDidDismiss', function (e) { console.log('didDismiss', e) })
@ -75,6 +79,7 @@
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: 'trash', icon: 'trash',
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }

View File

@ -19,6 +19,7 @@ export class ActionSheetExample {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: 'trash', icon: 'trash',
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }

View File

@ -8,6 +8,7 @@ async function presentActionSheet() {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: 'trash', icon: 'trash',
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }

View File

@ -72,6 +72,7 @@ export const ActionSheetExample: React.FC = () => {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: trash, icon: trash,
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }

View File

@ -16,6 +16,7 @@ export class ActionSheetExample {
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: 'trash', icon: 'trash',
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked'); console.log('Delete clicked');
} }

View File

@ -21,6 +21,7 @@ export default defineComponent({
text: 'Delete', text: 'Delete',
role: 'destructive', role: 'destructive',
icon: trash, icon: trash,
id: 'delete-button',
handler: () => { handler: () => {
console.log('Delete clicked') console.log('Delete clicked')
}, },

View File

@ -46,5 +46,6 @@ export interface AlertButton {
text: string; text: string;
role?: string; role?: string;
cssClass?: string | string[]; cssClass?: string | string[];
id?: string;
handler?: (value: any) => boolean | void | {[key: string]: any}; handler?: (value: any) => boolean | void | {[key: string]: any};
} }

View File

@ -538,7 +538,7 @@ export class Alert implements ComponentInterface, OverlayInterface {
return ( return (
<div class={alertButtonGroupClass}> <div class={alertButtonGroupClass}>
{buttons.map(button => {buttons.map(button =>
<button type="button" class={buttonClass(button)} tabIndex={0} onClick={() => this.buttonClick(button)}> <button type="button" id={button.id} class={buttonClass(button)} tabIndex={0} onClick={() => this.buttonClick(button)}>
<span class="alert-button-inner"> <span class="alert-button-inner">
{button.text} {button.text}
</span> </span>

View File

@ -99,11 +99,13 @@ export class AlertExample {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: (blah) => { handler: (blah) => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, { }, {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay'); console.log('Confirm Okay');
} }
@ -412,11 +414,13 @@ function presentAlertConfirm() {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: (blah) => { handler: (blah) => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, { }, {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay') console.log('Confirm Okay')
} }
@ -759,12 +763,14 @@ export const AlertExample: React.FC = () => {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: blah => { handler: blah => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, },
{ {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay'); console.log('Confirm Okay');
} }
@ -1064,11 +1070,13 @@ export class AlertExample {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: (blah) => { handler: (blah) => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, { }, {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay'); console.log('Confirm Okay');
} }
@ -1402,12 +1410,14 @@ export default defineComponent({
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: blah => { handler: blah => {
console.log('Confirm Cancel:', blah) console.log('Confirm Cancel:', blah)
}, },
}, },
{ {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay') console.log('Confirm Okay')
}, },

View File

@ -42,6 +42,9 @@
--min-width: 0; --min-width: 0;
--max-width: 200px; --max-width: 200px;
} }
#delete-button {
color: #eb445a;
}
</style> </style>
</ion-app> </ion-app>
@ -79,6 +82,7 @@
'Open Modal', 'Open Modal',
{ {
text: 'Delete', text: 'Delete',
id: 'delete-button',
role: 'destructive', role: 'destructive',
}, },
'Cancel', 'Cancel',
@ -185,6 +189,7 @@
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-id',
handler: () => { handler: () => {
console.log('Confirm Cancel') console.log('Confirm Cancel')
} }

View File

@ -185,6 +185,7 @@
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-id',
handler: () => { handler: () => {
console.log('Confirm Cancel') console.log('Confirm Cancel')
} }

View File

@ -165,6 +165,7 @@
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-id',
handler: () => { handler: () => {
console.log('Confirm Cancel') console.log('Confirm Cancel')
} }

View File

@ -48,11 +48,13 @@ export class AlertExample {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: (blah) => { handler: (blah) => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, { }, {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay'); console.log('Confirm Okay');
} }

View File

@ -36,11 +36,13 @@ function presentAlertConfirm() {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: (blah) => { handler: (blah) => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, { }, {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay') console.log('Confirm Okay')
} }

View File

@ -92,12 +92,14 @@ export const AlertExample: React.FC = () => {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: blah => { handler: blah => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, },
{ {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay'); console.log('Confirm Okay');
} }

View File

@ -45,11 +45,13 @@ export class AlertExample {
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: (blah) => { handler: (blah) => {
console.log('Confirm Cancel: blah'); console.log('Confirm Cancel: blah');
} }
}, { }, {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay'); console.log('Confirm Okay');
} }

View File

@ -53,12 +53,14 @@ export default defineComponent({
text: 'Cancel', text: 'Cancel',
role: 'cancel', role: 'cancel',
cssClass: 'secondary', cssClass: 'secondary',
id: 'cancel-button',
handler: blah => { handler: blah => {
console.log('Confirm Cancel:', blah) console.log('Confirm Cancel:', blah)
}, },
}, },
{ {
text: 'Okay', text: 'Okay',
id: 'confirm-button',
handler: () => { handler: () => {
console.log('Confirm Okay') console.log('Confirm Okay')
}, },