Skip to content

Commit

Permalink
fix: reposition column picker to always be visible (#1069)
Browse files Browse the repository at this point in the history
- similar to auto-positioning of Header Menu, we can auto-position left/right Column Picker with viewport available space
  • Loading branch information
ghiscoding authored Oct 6, 2024
1 parent ea3a119 commit ff4047f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/controls/slick.columnpicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,23 @@ export class SlickColumnPicker {

protected repositionMenu(event: DOMMouseOrTouchEvent<HTMLDivElement> | SlickEventData) {
const targetEvent: MouseEvent | Touch = (event as TouchEvent)?.touches?.[0] ?? event;
this._menuElm.style.top = `${targetEvent.pageY - 10}px`;
this._menuElm.style.left = `${targetEvent.pageX - 10}px`;
this._menuElm.style.maxHeight = `${window.innerHeight - targetEvent.clientY}px`;
this._menuElm.style.display = 'block';
this._menuElm.setAttribute('aria-expanded', 'true');
this._menuElm.appendChild(this._listElm);
if (this._menuElm) {
this._menuElm.style.display = 'block';

// auto-positioned menu left/right by available position
const gridPos = this.grid.getGridPosition();
const menuWidth = this._menuElm.clientWidth || 0;
let menuOffsetLeft = targetEvent.pageX || 0;
if (gridPos?.width && (menuOffsetLeft + menuWidth >= gridPos.width)) {
menuOffsetLeft = menuOffsetLeft - menuWidth;
}

this._menuElm.style.top = `${targetEvent.pageY - 10}px`;
this._menuElm.style.left = `${menuOffsetLeft}px`;
this._menuElm.style.maxHeight = `${window.innerHeight - targetEvent.clientY}px`;
this._menuElm.setAttribute('aria-expanded', 'true');
this._menuElm.appendChild(this._listElm);
}
}

protected updateColumnOrder() {
Expand Down

0 comments on commit ff4047f

Please sign in to comment.