Skip to content

Commit f6fc22b

Browse files
izyuumiliamdebeasi
andauthored
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 <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> 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? <!-- Please describe the behavior or changes that are being added by this PR. --> - 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 <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> I suggest there to be some global interface similar to the following: ``` interface LooseAutocomplete<T extends string> = T | Omit<string, T>; ``` I referenced this great [video](https://youtu.be/a_m7jxrTlaw) from Matt @mattpocock --------- Co-authored-by: Liam DeBeasi <[email protected]>
1 parent e021ead commit f6fc22b

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

core/src/components/action-sheet/action-sheet-interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnimationBuilder, Mode } from '../../interface';
1+
import type { AnimationBuilder, LiteralUnion, Mode } from '../../interface';
22

33
export interface ActionSheetOptions {
44
header?: string;
@@ -19,7 +19,7 @@ export interface ActionSheetOptions {
1919

2020
export interface ActionSheetButton<T = any> {
2121
text?: string;
22-
role?: 'cancel' | 'destructive' | 'selected' | string;
22+
role?: LiteralUnion<'cancel' | 'destructive' | 'selected', string>;
2323
icon?: string;
2424
cssClass?: string | string[];
2525
id?: string;

core/src/components/alert/alert-interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnimationBuilder, Mode, TextFieldTypes } from '../../interface';
1+
import type { AnimationBuilder, LiteralUnion, Mode, TextFieldTypes } from '../../interface';
22
import type { IonicSafeString } from '../../utils/sanitization';
33

44
export interface AlertOptions {
@@ -45,7 +45,7 @@ type AlertButtonOverlayHandler = boolean | void | { [key: string]: any };
4545

4646
export interface AlertButton {
4747
text: string;
48-
role?: 'cancel' | 'destructive' | string;
48+
role?: LiteralUnion<'cancel' | 'destructive', string>;
4949
cssClass?: string | string[];
5050
id?: string;
5151
htmlAttributes?: { [key: string]: any };

core/src/components/toast/toast-interface.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnimationBuilder, Color, Mode } from '../../interface';
1+
import type { AnimationBuilder, Color, LiteralUnion, Mode } from '../../interface';
22
import type { IonicSafeString } from '../../utils/sanitization';
33

44
export interface ToastOptions {
@@ -33,8 +33,7 @@ export interface ToastButton {
3333
text?: string;
3434
icon?: string;
3535
side?: 'start' | 'end';
36-
role?: 'cancel' | string;
37-
36+
role?: LiteralUnion<'cancel', string>;
3837
/**
3938
* @deprecated Use the toast button's CSS Shadow Parts instead.
4039
*/

core/src/interface.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export type PredefinedColors =
131131
| 'medium'
132132
| 'dark';
133133

134-
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
134+
export type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
135135

136136
export type Color = LiteralUnion<PredefinedColors, string>;
137137
export type Mode = 'ios' | 'md';

0 commit comments

Comments
 (0)