mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 11:17:19 +08:00
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 <liamdebeasi@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import type { AnimationBuilder, Mode } from '../../interface';
|
import type { AnimationBuilder, LiteralUnion, Mode } from '../../interface';
|
||||||
|
|
||||||
export interface ActionSheetOptions {
|
export interface ActionSheetOptions {
|
||||||
header?: string;
|
header?: string;
|
||||||
@ -19,7 +19,7 @@ export interface ActionSheetOptions {
|
|||||||
|
|
||||||
export interface ActionSheetButton<T = any> {
|
export interface ActionSheetButton<T = any> {
|
||||||
text?: string;
|
text?: string;
|
||||||
role?: 'cancel' | 'destructive' | 'selected' | string;
|
role?: LiteralUnion<'cancel' | 'destructive' | 'selected', string>;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
cssClass?: string | string[];
|
cssClass?: string | string[];
|
||||||
id?: string;
|
id?: string;
|
||||||
|
@ -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';
|
import type { IonicSafeString } from '../../utils/sanitization';
|
||||||
|
|
||||||
export interface AlertOptions {
|
export interface AlertOptions {
|
||||||
@ -45,7 +45,7 @@ type AlertButtonOverlayHandler = boolean | void | { [key: string]: any };
|
|||||||
|
|
||||||
export interface AlertButton {
|
export interface AlertButton {
|
||||||
text: string;
|
text: string;
|
||||||
role?: 'cancel' | 'destructive' | string;
|
role?: LiteralUnion<'cancel' | 'destructive', string>;
|
||||||
cssClass?: string | string[];
|
cssClass?: string | string[];
|
||||||
id?: string;
|
id?: string;
|
||||||
htmlAttributes?: { [key: string]: any };
|
htmlAttributes?: { [key: string]: any };
|
||||||
|
@ -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';
|
import type { IonicSafeString } from '../../utils/sanitization';
|
||||||
|
|
||||||
export interface ToastOptions {
|
export interface ToastOptions {
|
||||||
@ -33,8 +33,7 @@ export interface ToastButton {
|
|||||||
text?: string;
|
text?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
side?: 'start' | 'end';
|
side?: 'start' | 'end';
|
||||||
role?: 'cancel' | string;
|
role?: LiteralUnion<'cancel', string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use the toast button's CSS Shadow Parts instead.
|
* @deprecated Use the toast button's CSS Shadow Parts instead.
|
||||||
*/
|
*/
|
||||||
|
2
core/src/interface.d.ts
vendored
2
core/src/interface.d.ts
vendored
@ -131,7 +131,7 @@ export type PredefinedColors =
|
|||||||
| 'medium'
|
| 'medium'
|
||||||
| 'dark';
|
| 'dark';
|
||||||
|
|
||||||
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
export type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
||||||
|
|
||||||
export type Color = LiteralUnion<PredefinedColors, string>;
|
export type Color = LiteralUnion<PredefinedColors, string>;
|
||||||
export type Mode = 'ios' | 'md';
|
export type Mode = 'ios' | 'md';
|
||||||
|
Reference in New Issue
Block a user