Skip to content

Commit

Permalink
Toggle color picker popover clicking preview button
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarnef committed Sep 29, 2023
1 parent af8b738 commit 4f0781c
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions packages/uui-color-picker/lib/uui-color-picker.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
margin-left: 0.75rem;
border-radius: 50%;
}
color-picker__trigger {
cursor: pointer;
}
.color-picker__preview::before,
.color-picker__trigger::before {
content: '';
Expand Down Expand Up @@ -488,7 +485,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 @@ -497,7 +494,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 @@ -653,27 +650,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})`,
})}
@click=${this.openColorPicker}
aria-haspopup="true"
aria-expanded="false"></button>
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})`,
})}
@click=${this.openColorPicker}
aria-haspopup="true"
aria-expanded="false"></button>
<div slot="popover">${this._renderColorPicker()}</div>
</uui-popover>`;
}
Expand Down

0 comments on commit 4f0781c

Please sign in to comment.