From fcbf2416749dd6cbb47c30e8b1234d8fbdfe157a Mon Sep 17 00:00:00 2001 From: JC Franco Date: Wed, 22 Dec 2021 15:28:05 -0800 Subject: [PATCH 01/56] fix: ensure components are disabled consistently --- src/assets/styles/includes.scss | 12 ++ .../calcite-action/calcite-action.scss | 4 +- .../calcite-action/calcite-action.tsx | 3 +- .../calcite-block/calcite-block.scss | 13 +-- .../calcite-block/calcite-block.tsx | 18 ++- .../calcite-button/calcite-button.scss | 6 +- .../calcite-button/calcite-button.tsx | 3 +- .../calcite-checkbox/calcite-checkbox.scss | 4 +- .../calcite-checkbox/calcite-checkbox.tsx | 9 +- .../calcite-color-picker.scss | 2 + .../calcite-color-picker.tsx | 10 ++ .../calcite-combobox-item.scss | 2 + .../calcite-combobox-item.tsx | 7 +- .../calcite-combobox/calcite-combobox.scss | 4 +- .../calcite-combobox/calcite-combobox.tsx | 17 ++- .../calcite-date-picker-day.scss | 7 +- .../calcite-date-picker-day.tsx | 7 +- .../calcite-dropdown/calcite-dropdown.scss | 6 +- .../calcite-dropdown/calcite-dropdown.tsx | 23 +++- src/components/calcite-fab/calcite-fab.scss | 2 + src/components/calcite-fab/calcite-fab.tsx | 3 +- .../calcite-filter/calcite-filter.scss | 2 + .../calcite-filter/calcite-filter.tsx | 4 +- .../calcite-inline-editable.scss | 3 +- .../calcite-inline-editable.tsx | 3 +- .../calcite-input-date-picker.scss | 14 ++- .../calcite-input-date-picker.tsx | 25 ++++- .../calcite-input-time-picker.scss | 1 + .../calcite-input-time-picker.tsx | 21 +++- .../calcite-input/calcite-input.scss | 6 +- .../calcite-input/calcite-input.tsx | 11 +- .../calcite-label/calcite-label.scss | 4 +- .../calcite-label/calcite-label.tsx | 6 +- src/components/calcite-link/calcite-link.scss | 11 +- src/components/calcite-link/calcite-link.tsx | 9 +- .../calcite-list-item/calcite-list-item.scss | 4 +- .../calcite-list-item/calcite-list-item.tsx | 13 ++- src/components/calcite-list/calcite-list.scss | 2 + src/components/calcite-list/calcite-list.tsx | 18 ++- .../calcite-panel/calcite-panel.scss | 2 + .../calcite-panel/calcite-panel.tsx | 13 ++- .../calcite-pick-list/calcite-pick-list.scss | 2 + .../calcite-pick-list/calcite-pick-list.tsx | 8 +- .../calcite-pick-list/shared-list-render.tsx | 2 +- .../calcite-radio-button.scss | 3 +- .../calcite-radio-button.tsx | 9 +- .../calcite-radio-group.scss | 7 +- .../calcite-radio-group.tsx | 3 +- .../calcite-rating/calcite-rating.scss | 6 +- .../calcite-rating/calcite-rating.tsx | 8 +- .../calcite-select/calcite-select.scss | 6 +- .../calcite-select/calcite-select.tsx | 3 +- .../calcite-slider/calcite-slider.scss | 3 +- .../calcite-slider/calcite-slider.tsx | 3 +- .../calcite-sortable-list.scss | 2 + .../calcite-sortable-list.tsx | 7 +- .../calcite-split-button.scss | 2 +- .../calcite-split-button.tsx | 22 +++- .../calcite-stepper-item.scss | 11 +- .../calcite-stepper-item.tsx | 15 +-- .../calcite-switch/calcite-switch.scss | 5 +- .../calcite-switch/calcite-switch.tsx | 10 +- .../calcite-tab-title/calcite-tab-title.scss | 3 +- .../calcite-tab-title/calcite-tab-title.tsx | 4 +- .../calcite-tile-select.scss | 106 +++++++++++++++++- .../calcite-tile-select.tsx | 5 +- src/components/calcite-tile/calcite-tile.scss | 12 +- src/components/calcite-tile/calcite-tile.tsx | 3 +- .../calcite-value-list.scss | 2 + .../calcite-value-list/calcite-value-list.tsx | 8 +- src/tests/commonTests.ts | 22 ++++ src/utils/interactive.ts | 37 ++++++ 72 files changed, 524 insertions(+), 149 deletions(-) create mode 100644 src/utils/interactive.ts diff --git a/src/assets/styles/includes.scss b/src/assets/styles/includes.scss index 151624b7e1c..402c1909f64 100644 --- a/src/assets/styles/includes.scss +++ b/src/assets/styles/includes.scss @@ -41,3 +41,15 @@ z-index: -1 !important; } } + +@mixin disabled() { + :host([disabled]) { + @apply cursor-default opacity-disabled pointer-events-none select-none; + @content; + + [calcite-hydrated][disabled] { + /* prevent opacity stacking */ + @apply opacity-100; + } + } +} diff --git a/src/components/calcite-action/calcite-action.scss b/src/components/calcite-action/calcite-action.scss index 52ceb8df0fd..d44f386ed4e 100755 --- a/src/components/calcite-action/calcite-action.scss +++ b/src/components/calcite-action/calcite-action.scss @@ -3,9 +3,7 @@ @apply flex bg-transparent; } -:host([disabled]) { - @apply pointer-events-none; -} +@include disabled(); .button { @apply bg-foreground-1 diff --git a/src/components/calcite-action/calcite-action.tsx b/src/components/calcite-action/calcite-action.tsx index c772c43107d..556c141f8ea 100755 --- a/src/components/calcite-action/calcite-action.tsx +++ b/src/components/calcite-action/calcite-action.tsx @@ -16,6 +16,7 @@ import { Alignment, Appearance, Scale } from "../interfaces"; import { CSS, TEXT } from "./resources"; import { createObserver } from "../../utils/observers"; +import { InteractiveComponent } from "../../utils/interactive"; /** * @slot - A slot for adding a `calcite-icon`. @@ -25,7 +26,7 @@ import { createObserver } from "../../utils/observers"; styleUrl: "calcite-action.scss", shadow: true }) -export class CalciteAction { +export class CalciteAction implements InteractiveComponent { // -------------------------------------------------------------------------- // // Properties diff --git a/src/components/calcite-block/calcite-block.scss b/src/components/calcite-block/calcite-block.scss index 2bb33081fe4..e9c472d9ffe 100644 --- a/src/components/calcite-block/calcite-block.scss +++ b/src/components/calcite-block/calcite-block.scss @@ -17,6 +17,8 @@ flex-basis: auto; } +@include disabled(); + @import "../../assets/styles/header"; .header { @@ -161,14 +163,3 @@ calcite-action-menu { @apply text-color-1; } } - -:host([disabled]) { - pointer-events: none; - user-select: none; - - @apply pointer-events-none select-none; - - .header-container { - @apply opacity-50; - } -} diff --git a/src/components/calcite-block/calcite-block.tsx b/src/components/calcite-block/calcite-block.tsx index 8d3f5601fcd..ee043bd0535 100644 --- a/src/components/calcite-block/calcite-block.tsx +++ b/src/components/calcite-block/calcite-block.tsx @@ -8,6 +8,7 @@ import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot"; +import { InteractiveComponent, updateHostInteraction } from "../../utils/interactive"; /** * @slot - A slot for adding content to the block. @@ -20,7 +21,7 @@ import { styleUrl: "calcite-block.scss", shadow: true }) -export class CalciteBlock implements ConditionalSlotComponent { +export class CalciteBlock implements ConditionalSlotComponent, InteractiveComponent { // -------------------------------------------------------------------------- // // Properties @@ -92,6 +93,16 @@ export class CalciteBlock implements ConditionalSlotComponent { */ @Prop() summary: string; + //-------------------------------------------------------------------------- + // + // Lifecycle + // + //-------------------------------------------------------------------------- + + componentDidRender(): void { + updateHostInteraction(this); + } + // -------------------------------------------------------------------------- // // Private Properties @@ -190,8 +201,7 @@ export class CalciteBlock implements ConditionalSlotComponent { } render(): VNode { - const { collapsible, disabled, el, intlCollapse, intlExpand, loading, open, intlLoading } = - this; + const { collapsible, el, intlCollapse, intlExpand, loading, open, intlLoading } = this; const toggleLabel = open ? intlCollapse || TEXT.collapse : intlExpand || TEXT.expand; @@ -246,7 +256,7 @@ export class CalciteBlock implements ConditionalSlotComponent { ); return ( - +
); } + + componentDidRender(): void { + updateHostInteraction(this); + } } diff --git a/src/components/calcite-dropdown/calcite-dropdown.scss b/src/components/calcite-dropdown/calcite-dropdown.scss index 5dd286d1699..0514d4ff561 100644 --- a/src/components/calcite-dropdown/calcite-dropdown.scss +++ b/src/components/calcite-dropdown/calcite-dropdown.scss @@ -10,10 +10,8 @@ @apply inline-flex flex-initial; } -// disabled styles -:host([disabled]) { - @apply pointer-events-none opacity-disabled; -} +@include disabled(); + :host .calcite-dropdown-wrapper { @include popperContainer(); @include popperWrapper(); diff --git a/src/components/calcite-dropdown/calcite-dropdown.tsx b/src/components/calcite-dropdown/calcite-dropdown.tsx index 093cc4a54ba..36a2091bcbf 100644 --- a/src/components/calcite-dropdown/calcite-dropdown.tsx +++ b/src/components/calcite-dropdown/calcite-dropdown.tsx @@ -24,6 +24,7 @@ import { Instance as Popper, StrictModifiers } from "@popperjs/core"; import { Scale } from "../interfaces"; import { DefaultDropdownPlacement, SLOTS } from "./resources"; import { createObserver } from "../../utils/observers"; +import { InteractiveComponent, updateHostInteraction } from "../../utils/interactive"; /** * @slot - A slot for adding `calcite-dropdown-group`s or `calcite-dropdown-item`s. @@ -34,7 +35,7 @@ import { createObserver } from "../../utils/observers"; styleUrl: "calcite-dropdown.scss", shadow: true }) -export class CalciteDropdown { +export class CalciteDropdown implements InteractiveComponent { //-------------------------------------------------------------------------- // // Element @@ -54,7 +55,12 @@ export class CalciteDropdown { @Watch("active") activeHandler(): void { - this.reposition(); + if (!this.disabled) { + this.reposition(); + return; + } + + this.active = false; } /** @@ -66,6 +72,13 @@ export class CalciteDropdown { /** is the dropdown disabled */ @Prop({ reflect: true }) disabled = false; + @Watch("disabled") + handleDisabledChange(value: boolean): void { + if (!value) { + this.active = false; + } + } + /** specify the maximum number of calcite-dropdown-items to display before showing the scroller, must be greater than 0 - this value does not include groupTitles passed to calcite-dropdown-group @@ -124,6 +137,10 @@ export class CalciteDropdown { this.reposition(); } + componentDidRender(): void { + updateHostInteraction(this); + } + disconnectedCallback(): void { this.mutationObserver?.disconnect(); this.resizeObserver?.disconnect(); @@ -134,7 +151,7 @@ export class CalciteDropdown { const { active } = this; return ( - +
diff --git a/src/components/calcite-inline-editable/calcite-inline-editable.scss b/src/components/calcite-inline-editable/calcite-inline-editable.scss index 2e62d045542..867a7af32e0 100755 --- a/src/components/calcite-inline-editable/calcite-inline-editable.scss +++ b/src/components/calcite-inline-editable/calcite-inline-editable.scss @@ -44,7 +44,8 @@ @apply flex; } -:host([disabled]) { +// TODO: Test +@include disabled() { .cancel-editing-button-wrapper { @apply border-color-2; } diff --git a/src/components/calcite-inline-editable/calcite-inline-editable.tsx b/src/components/calcite-inline-editable/calcite-inline-editable.tsx index 9f834beee41..d5a42f425e6 100644 --- a/src/components/calcite-inline-editable/calcite-inline-editable.tsx +++ b/src/components/calcite-inline-editable/calcite-inline-editable.tsx @@ -15,6 +15,7 @@ import { Scale } from "../interfaces"; import { TEXT, CSS } from "./resources"; import { connectLabel, disconnectLabel, getLabelText, LabelableComponent } from "../../utils/label"; import { createObserver } from "../../utils/observers"; +import { InteractiveComponent } from "../../utils/interactive"; /** * @slot - A slot for adding a `calcite-input`. @@ -24,7 +25,7 @@ import { createObserver } from "../../utils/observers"; shadow: true, styleUrl: "calcite-inline-editable.scss" }) -export class CalciteInlineEditable implements LabelableComponent { +export class CalciteInlineEditable implements InteractiveComponent, LabelableComponent { //-------------------------------------------------------------------------- // // Element diff --git a/src/components/calcite-input-date-picker/calcite-input-date-picker.scss b/src/components/calcite-input-date-picker/calcite-input-date-picker.scss index eb3c0e8baab..6affa804679 100644 --- a/src/components/calcite-input-date-picker/calcite-input-date-picker.scss +++ b/src/components/calcite-input-date-picker/calcite-input-date-picker.scss @@ -1,6 +1,5 @@ :host { @extend %component-spacing; - @include popperElemAnim(".menu-container"); @apply shadow-none inline-block align-top @@ -9,6 +8,8 @@ overflow-visible; } +@include disabled(); + .calendar-picker-wrapper { @apply shadow-none static @@ -88,12 +89,13 @@ .menu-container { @include popperContainer(); - @apply invisible - pointer-events-none; + @include popperWrapper(); } -:host([active]) .menu-container { - @apply visible - pointer-events-auto; + +@include popperElemAnim(".menu-container"); + +.menu-container--active { + @include popperElemAnim(".menu-container"); } .input .calcite-input__wrapper { diff --git a/src/components/calcite-input-date-picker/calcite-input-date-picker.tsx b/src/components/calcite-input-date-picker/calcite-input-date-picker.tsx index af3dfaea8a4..8eaa6f58986 100644 --- a/src/components/calcite-input-date-picker/calcite-input-date-picker.tsx +++ b/src/components/calcite-input-date-picker/calcite-input-date-picker.tsx @@ -35,6 +35,7 @@ import { } from "../../utils/popper"; import { StrictModifiers, Instance as Popper } from "@popperjs/core"; import { DateRangeChange } from "../calcite-date-picker/interfaces"; +import { InteractiveComponent } from "../../utils/interactive"; const DEFAULT_PLACEMENT = "bottom-leading"; @@ -43,7 +44,9 @@ const DEFAULT_PLACEMENT = "bottom-leading"; styleUrl: "calcite-input-date-picker.scss", shadow: true }) -export class CalciteInputDatePicker implements LabelableComponent, FormComponent { +export class CalciteInputDatePicker + implements LabelableComponent, FormComponent, InteractiveComponent +{ //-------------------------------------------------------------------------- // // Element @@ -61,6 +64,13 @@ export class CalciteInputDatePicker implements LabelableComponent, FormComponent */ @Prop({ reflect: true }) disabled = false; + @Watch("disabled") + handleDisabledChange(value: boolean): void { + if (!value) { + this.active = false; + } + } + /** Selected date */ @Prop({ mutable: true }) value: string | string[]; @@ -128,7 +138,12 @@ export class CalciteInputDatePicker implements LabelableComponent, FormComponent @Watch("active") activeHandler(): void { - this.reposition(); + if (!this.disabled) { + this.reposition(); + return; + } + + this.active = false; } /** @@ -360,10 +375,12 @@ export class CalciteInputDatePicker implements LabelableComponent, FormComponent />
} -