Skip to content

Toggle color picker popover clicking preview button #589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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