From c50b57d96be9d8e45162135fab7dc71ed5fee15d Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Tue, 30 Mar 2021 08:44:41 -0400 Subject: [PATCH] tidy up color picker --- docs/resources/changelog.md | 1 + src/components/color-picker/color-picker.ts | 22 +++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/resources/changelog.md b/docs/resources/changelog.md index 39f4334c..81140540 100644 --- a/docs/resources/changelog.md +++ b/docs/resources/changelog.md @@ -9,6 +9,7 @@ _During the beta period, these restrictions may be relaxed in the event of a mis ## Next - Fixed a bug where toggling `open` on `sl-drawer` would skip the transition +- Fixed a bug where `sl-color-picker` could be opened when disabled - Renamed `components.json` to `metadata.json` - Updated to the prerelease versions of LitElement and lit-html diff --git a/src/components/color-picker/color-picker.ts b/src/components/color-picker/color-picker.ts index 2da9e7e4..d7e9166d 100644 --- a/src/components/color-picker/color-picker.ts +++ b/src/components/color-picker/color-picker.ts @@ -1,6 +1,7 @@ import { LitElement, html, unsafeCSS } from 'lit'; import { customElement, property, query, state } from 'lit/decorators'; import { classMap } from 'lit-html/directives/class-map'; +import { ifDefined } from 'lit-html/directives/if-defined'; import { styleMap } from 'lit-html/directives/style-map'; import { event, EventEmitter, watch } from '../../internal/decorators'; import styles from 'sass:./color-picker.scss'; @@ -96,7 +97,7 @@ export default class SlColorPicker extends LitElement { * An array of predefined color swatches to display. Can include any format the color picker can parse, including * HEX(A), RGB(A), HSL(A), and CSS color names. */ - @property() swatches = [ + @property({ attribute: false }) swatches = [ '#d0021b', '#f5a623', '#f8e71c', @@ -127,7 +128,7 @@ export default class SlColorPicker extends LitElement { /** Emitted when the color picker closes. Calling `event.preventDefault()` will prevent it from being closed. */ @event('sl-hide') slHide: EventEmitter; - /** Emitted after the color picker closes and all transitions are complete. */ + /** Emitted after the color picker closes and all transitions are complete. */ @event('sl-after-hide') slAfterHide: EventEmitter; connectedCallback() { @@ -387,7 +388,12 @@ export default class SlColorPicker extends LitElement { handleDropdownShow(event: CustomEvent) { event.stopPropagation(); - this.slShow.emit(); + + if (this.disabled) { + event.preventDefault(); + } else { + this.slShow.emit(); + } } handleDropdownAfterShow(event: CustomEvent) { @@ -646,7 +652,7 @@ export default class SlColorPicker extends LitElement { aria-valuetext=${`hsl(${Math.round(this.hue)}, ${Math.round(this.saturation)}%, ${Math.round( this.lightness )}%)`} - tabindex=${this.disabled ? null : '0'} + tabindex=${ifDefined(this.disabled ? undefined : '0')} @keydown=${this.handleGridKeyDown} > @@ -671,7 +677,7 @@ export default class SlColorPicker extends LitElement { aria-valuemin="0" aria-valuemax="360" aria-valuenow=${Math.round(this.hue)} - tabindex=${this.disabled ? null : 0} + tabindex=${ifDefined(this.disabled ? undefined : '0')} @keydown=${this.handleHueKeyDown} > @@ -706,7 +712,7 @@ export default class SlColorPicker extends LitElement { aria-valuemin="0" aria-valuemax="100" aria-valuenow=${Math.round(this.alpha)} - tabindex=${this.disabled ? null : '0'} + tabindex=${ifDefined(this.disabled ? undefined : '0')} @keydown=${this.handleAlphaKeyDown} > @@ -767,7 +773,7 @@ export default class SlColorPicker extends LitElement {
!this.disabled && this.setColor(swatch)} @@ -795,7 +801,7 @@ export default class SlColorPicker extends LitElement { class="color-dropdown" aria-disabled=${this.disabled ? 'true' : 'false'} .containing-element=${this} - hoist=${this.hoist} + ?hoist=${this.hoist} @sl-show=${this.handleDropdownShow} @sl-after-show=${this.handleDropdownAfterShow} @sl-hide=${this.handleDropdownHide}