From e76d72989a9f18a52d9a6a8d1dd64e84a9c1e668 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 19 Dec 2023 16:48:25 -0500 Subject: [PATCH] feat(action-sheet): add disabled button (#28723) Issue number: N/A --------- ## What is the current behavior? Action sheet buttons cannot be disabled. This behavior exists in iOS 17. ## What is the new behavior? - Action sheet buttons can be disabled ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information --------- Co-authored-by: ionitron --- core/api.txt | 1 + .../action-sheet/action-sheet-interface.ts | 8 ++++ .../action-sheet/action-sheet.ios.scss | 1 + .../action-sheet/action-sheet.md.scss | 1 + .../components/action-sheet/action-sheet.scss | 9 ++++- .../components/action-sheet/action-sheet.tsx | 10 ++++- .../test/basic/action-sheet-rendering.e2e.ts | 26 ++++++++++++ ...t-disabled-ios-ltr-Mobile-Chrome-linux.png | Bin 0 -> 5309 bytes ...-disabled-ios-ltr-Mobile-Firefox-linux.png | Bin 0 -> 10091 bytes ...t-disabled-ios-ltr-Mobile-Safari-linux.png | Bin 0 -> 4725 bytes ...et-disabled-md-ltr-Mobile-Chrome-linux.png | Bin 0 -> 4203 bytes ...t-disabled-md-ltr-Mobile-Firefox-linux.png | Bin 0 -> 8791 bytes ...et-disabled-md-ltr-Mobile-Safari-linux.png | Bin 0 -> 3619 bytes .../test/basic/action-sheet.spec.tsx | 37 ++++++++++++++++++ core/src/utils/gesture/button-active.ts | 2 +- 15 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 core/src/components/action-sheet/test/basic/action-sheet-rendering.e2e.ts-snapshots/action-sheet-disabled-ios-ltr-Mobile-Chrome-linux.png create mode 100644 core/src/components/action-sheet/test/basic/action-sheet-rendering.e2e.ts-snapshots/action-sheet-disabled-ios-ltr-Mobile-Firefox-linux.png create mode 100644 core/src/components/action-sheet/test/basic/action-sheet-rendering.e2e.ts-snapshots/action-sheet-disabled-ios-ltr-Mobile-Safari-linux.png create mode 100644 core/src/components/action-sheet/test/basic/action-sheet-rendering.e2e.ts-snapshots/action-sheet-disabled-md-ltr-Mobile-Chrome-linux.png create mode 100644 core/src/components/action-sheet/test/basic/action-sheet-rendering.e2e.ts-snapshots/action-sheet-disabled-md-ltr-Mobile-Firefox-linux.png create mode 100644 core/src/components/action-sheet/test/basic/action-sheet-rendering.e2e.ts-snapshots/action-sheet-disabled-md-ltr-Mobile-Safari-linux.png diff --git a/core/api.txt b/core/api.txt index 39441b584f..a242f01889 100644 --- a/core/api.txt +++ b/core/api.txt @@ -60,6 +60,7 @@ ion-action-sheet,css-prop,--button-background-selected ion-action-sheet,css-prop,--button-background-selected-opacity ion-action-sheet,css-prop,--button-color ion-action-sheet,css-prop,--button-color-activated +ion-action-sheet,css-prop,--button-color-disabled ion-action-sheet,css-prop,--button-color-focused ion-action-sheet,css-prop,--button-color-hover ion-action-sheet,css-prop,--button-color-selected diff --git a/core/src/components/action-sheet/action-sheet-interface.ts b/core/src/components/action-sheet/action-sheet-interface.ts index 465c50e050..90e4e99a26 100644 --- a/core/src/components/action-sheet/action-sheet-interface.ts +++ b/core/src/components/action-sheet/action-sheet-interface.ts @@ -26,4 +26,12 @@ export interface ActionSheetButton { htmlAttributes?: { [key: string]: any }; handler?: () => boolean | void | Promise; data?: T; + /** + * When `disabled` is `true` the action + * sheet button will not be interactive. Note + * that buttons with a 'cancel' role cannot + * be disabled as that would make it difficult for + * users to dismiss the action sheet. + */ + disabled?: boolean; } diff --git a/core/src/components/action-sheet/action-sheet.ios.scss b/core/src/components/action-sheet/action-sheet.ios.scss index 594b735386..bf591b9493 100644 --- a/core/src/components/action-sheet/action-sheet.ios.scss +++ b/core/src/components/action-sheet/action-sheet.ios.scss @@ -17,6 +17,7 @@ --button-background-selected: #{$action-sheet-ios-button-background-selected}; --button-background-selected-opacity: 1; --button-color: #{$action-sheet-ios-button-text-color}; + --button-color-disabled: #{$text-color-step-150}; --color: #{$action-sheet-ios-title-color}; text-align: $action-sheet-ios-text-align; diff --git a/core/src/components/action-sheet/action-sheet.md.scss b/core/src/components/action-sheet/action-sheet.md.scss index 17076563c3..e3480feefe 100644 --- a/core/src/components/action-sheet/action-sheet.md.scss +++ b/core/src/components/action-sheet/action-sheet.md.scss @@ -17,6 +17,7 @@ --button-background-focused: currentColor; --button-background-focused-opacity: .12; --button-color: #{$action-sheet-md-button-text-color}; + --button-color-disabled: var(--button-color); --color: #{$action-sheet-md-title-color}; } diff --git a/core/src/components/action-sheet/action-sheet.scss b/core/src/components/action-sheet/action-sheet.scss index b6b91e7330..2519c214f3 100644 --- a/core/src/components/action-sheet/action-sheet.scss +++ b/core/src/components/action-sheet/action-sheet.scss @@ -33,6 +33,7 @@ * @prop --button-color-hover: Color of the action sheet button on hover * @prop --button-color-focused: Color of the action sheet button when tabbed to * @prop --button-color-selected: Color of the selected action sheet button + * @prop --button-color-disabled: Color of the selected action sheet button when disabled */ --color: initial; --button-color-activated: var(--button-color); @@ -102,6 +103,12 @@ overflow: hidden; } +.action-sheet-button:disabled { + color: var(--button-color-disabled); + + opacity: 0.4; +} + .action-sheet-button-inner { display: flex; @@ -220,7 +227,7 @@ // -------------------------------------------------- @media (any-hover: hover) { - .action-sheet-button:hover { + .action-sheet-button:not(:disabled):hover { color: var(--button-color-hover); &::after { diff --git a/core/src/components/action-sheet/action-sheet.tsx b/core/src/components/action-sheet/action-sheet.tsx index 984e24cdaa..4805772b29 100644 --- a/core/src/components/action-sheet/action-sheet.tsx +++ b/core/src/components/action-sheet/action-sheet.tsx @@ -403,6 +403,7 @@ export class ActionSheet implements ComponentInterface, OverlayInterface { id={b.id} class={buttonClass(b)} onClick={() => this.buttonClick(b)} + disabled={b.disabled} > {b.icon &&