From f6fc22bba60388701b80a9421510e3d843d39e9e Mon Sep 17 00:00:00 2001 From: Yumi Izumi Date: Tue, 30 Jan 2024 09:53:40 -0500 Subject: [PATCH] fix(action-sheet, alert, toast): button roles autocomplete with available options (#27940) Issue number: resolves #27965 --------- https://www.youtube.com/watch?v=a_m7jxrTlaw&list=PLIvujZeVDLMx040-j1W4WFs1BxuTGdI_b&index=3 ## What is the current behavior? There is a lack of autocomplete support for AlertButton attribute of `role` (there may be similar situations for other components too, however, I was working on this component and found it). ## What is the new behavior? - Support for autocomplete for the two types defined `cancel` and `destructive`, and also supports any arbitrary string if passed in. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information I suggest there to be some global interface similar to the following: ``` interface LooseAutocomplete = T | Omit; ``` I referenced this great [video](https://youtu.be/a_m7jxrTlaw) from Matt @mattpocock --------- Co-authored-by: Liam DeBeasi --- core/src/components/action-sheet/action-sheet-interface.ts | 4 ++-- core/src/components/alert/alert-interface.ts | 4 ++-- core/src/components/toast/toast-interface.ts | 5 ++--- core/src/interface.d.ts | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/components/action-sheet/action-sheet-interface.ts b/core/src/components/action-sheet/action-sheet-interface.ts index 465c50e050..1021895d0e 100644 --- a/core/src/components/action-sheet/action-sheet-interface.ts +++ b/core/src/components/action-sheet/action-sheet-interface.ts @@ -1,4 +1,4 @@ -import type { AnimationBuilder, Mode } from '../../interface'; +import type { AnimationBuilder, LiteralUnion, Mode } from '../../interface'; export interface ActionSheetOptions { header?: string; @@ -19,7 +19,7 @@ export interface ActionSheetOptions { export interface ActionSheetButton { text?: string; - role?: 'cancel' | 'destructive' | 'selected' | string; + role?: LiteralUnion<'cancel' | 'destructive' | 'selected', string>; icon?: string; cssClass?: string | string[]; id?: string; diff --git a/core/src/components/alert/alert-interface.ts b/core/src/components/alert/alert-interface.ts index 3f9d6cda8d..326d74484d 100644 --- a/core/src/components/alert/alert-interface.ts +++ b/core/src/components/alert/alert-interface.ts @@ -1,4 +1,4 @@ -import type { AnimationBuilder, Mode, TextFieldTypes } from '../../interface'; +import type { AnimationBuilder, LiteralUnion, Mode, TextFieldTypes } from '../../interface'; import type { IonicSafeString } from '../../utils/sanitization'; export interface AlertOptions { @@ -45,7 +45,7 @@ type AlertButtonOverlayHandler = boolean | void | { [key: string]: any }; export interface AlertButton { text: string; - role?: 'cancel' | 'destructive' | string; + role?: LiteralUnion<'cancel' | 'destructive', string>; cssClass?: string | string[]; id?: string; htmlAttributes?: { [key: string]: any }; diff --git a/core/src/components/toast/toast-interface.ts b/core/src/components/toast/toast-interface.ts index d5ddff69e4..af320f59ba 100644 --- a/core/src/components/toast/toast-interface.ts +++ b/core/src/components/toast/toast-interface.ts @@ -1,4 +1,4 @@ -import type { AnimationBuilder, Color, Mode } from '../../interface'; +import type { AnimationBuilder, Color, LiteralUnion, Mode } from '../../interface'; import type { IonicSafeString } from '../../utils/sanitization'; export interface ToastOptions { @@ -33,8 +33,7 @@ export interface ToastButton { text?: string; icon?: string; side?: 'start' | 'end'; - role?: 'cancel' | string; - + role?: LiteralUnion<'cancel', string>; /** * @deprecated Use the toast button's CSS Shadow Parts instead. */ diff --git a/core/src/interface.d.ts b/core/src/interface.d.ts index 3ac6705855..83ae6e2b6b 100644 --- a/core/src/interface.d.ts +++ b/core/src/interface.d.ts @@ -131,7 +131,7 @@ export type PredefinedColors = | 'medium' | 'dark'; -type LiteralUnion = T | (U & Record); +export type LiteralUnion = T | (U & Record); export type Color = LiteralUnion; export type Mode = 'ios' | 'md';