Skip to content

Commit

Permalink
Merge pull request #589 from bjarnef/feature/color-picker-toggle
Browse files Browse the repository at this point in the history
Toggle color picker popover clicking preview button
  • Loading branch information
loivsen authored Oct 16, 2023
2 parents fc61c8b + 6763230 commit bb839af
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions packages/uui-color-picker/lib/uui-color-picker.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
event.stopImmediatePropagation();

const target = event.target as HTMLElement;
const popover = target.nextElementSibling as UUIPopoverElement;
const popover = target.parentElement as UUIPopoverElement;

popover.open = !popover?.open;

Expand All @@ -498,7 +498,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {

closeColorPicker(event: Event) {
const target = event.target as UUIPopoverElement;
const trigger = target.previousElementSibling;
const trigger = target.querySelector("button[part=trigger]");

if (trigger) {
trigger.setAttribute('aria-expanded', 'false');
Expand Down Expand Up @@ -661,28 +661,29 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
}

private _renderPreviewButton() {
return html`<button
type="button"
slot="trigger"
aria-label="${this.label || 'Open Color picker'}"
class=${classMap({
'color-picker__trigger': true,
'color-dropdown__trigger--disabled': this.disabled,
'color-dropdown__trigger--small': this.size === 'small',
'color-dropdown__trigger--medium': this.size === 'medium',
'color-dropdown__trigger--large': this.size === 'large',
'color-picker__transparent-bg': true,
})}
style=${styleMap({
'--preview-color': `hsla(${this.hue}deg, ${this.saturation}%, ${
this.lightness
}%, ${this.alpha / 100})`,
})}
?disabled=${this.disabled}
@click=${this.openColorPicker}
aria-haspopup="true"
aria-expanded="false"></button>
<uui-popover placement="bottom-start" @close=${this.closeColorPicker}>
return html`<uui-popover placement="bottom-start" @close=${this.closeColorPicker}>
<button
type="button"
part="trigger"
slot="trigger"
aria-label="${this.label || 'Open Color picker'}"
class=${classMap({
'color-picker__trigger': true,
'color-dropdown__trigger--disabled': this.disabled,
'color-dropdown__trigger--small': this.size === 'small',
'color-dropdown__trigger--medium': this.size === 'medium',
'color-dropdown__trigger--large': this.size === 'large',
'color-picker__transparent-bg': true,
})}
style=${styleMap({
'--preview-color': `hsla(${this.hue}deg, ${this.saturation}%, ${
this.lightness
}%, ${this.alpha / 100})`,
})}
?disabled=${this.disabled}
@click=${this.openColorPicker}
aria-haspopup="true"
aria-expanded="false"></button>
<div slot="popover">${this._renderColorPicker()}</div>
</uui-popover>`;
}
Expand Down

0 comments on commit bb839af

Please sign in to comment.