Skip to content
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

Color picker fixes #365

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/components/ColorPicker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ class ColorPicker extends Element implements IBindable {
this.dom.addEventListener('focus', this._onFocus);
this.dom.addEventListener('blur', this._onBlur);

this.on('click', () => {
this.dom.addEventListener('pointerdown', (evt) => {
if (this.enabled && !this.readOnly) {
this._openColorPicker();

evt.stopPropagation();
evt.preventDefault();
}
});

Expand Down Expand Up @@ -375,7 +378,7 @@ class ColorPicker extends Element implements IBindable {
// position picker
const rectPicker = this._overlay.dom.getBoundingClientRect();
const rectElement = this.dom.getBoundingClientRect();
this._setColorPickerPosition(rectElement.left - rectElement.width, rectElement.top + 25);
this._setColorPickerPosition(rectElement.left - rectPicker.left, rectElement.bottom - rectPicker.top + 1);

// color changed, update picker
this._evtColorToPicker = this.on('change', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/components/Overlay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Overlay extends Container {
this._domClickableOverlay.classList.add(CLASS_OVERLAY_INNER);
this.dom.appendChild(this._domClickableOverlay);

this._domClickableOverlay.addEventListener('mousedown', this._onMouseDown);
this._domClickableOverlay.addEventListener('pointerdown', this._onPointerDown);

this.domContent = document.createElement('div');
this.domContent.ui = this;
Expand All @@ -56,12 +56,12 @@ class Overlay extends Container {
destroy() {
if (this._destroyed) return;

this._domClickableOverlay.removeEventListener('mousedown', this._onMouseDown);
this._domClickableOverlay.removeEventListener('pointerdown', this._onPointerDown);

super.destroy();
}

protected _onMouseDown = (evt: MouseEvent) => {
protected _onPointerDown = (evt: MouseEvent) => {
if (!this.clickable) return;

// some field might be in focus
Expand All @@ -73,6 +73,7 @@ class Overlay extends Container {
});

evt.preventDefault();
evt.stopPropagation();
};

/**
Expand Down
Loading