Skip to content

Commit

Permalink
fix: add resizeObserver to trigger popper update #270
Browse files Browse the repository at this point in the history
  • Loading branch information
rmenner committed Dec 19, 2024
1 parent f9392df commit bac19b1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/auro-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class AuroDropdown extends LitElement {
this.isPopoverVisible = false;
this.matchWidth = false;
this.noHideOnThisFocusLoss = false;
this.resizeObserver = null;

this.privateDefaults();
}
Expand Down Expand Up @@ -337,6 +338,8 @@ export class AuroDropdown extends LitElement {
});

this.notifyReady();

this.setUpResizeObserver();
}

/**
Expand Down Expand Up @@ -365,6 +368,7 @@ export class AuroDropdown extends LitElement {
this.triggerChevron.removeAttribute('data-expanded');
}
this.dispatchEventDropdownToggle();
this.resizeObserver.unobserve(this.trigger);
}

/**
Expand All @@ -388,8 +392,8 @@ export class AuroDropdown extends LitElement {
}

this.handleFocusLoss();

this.dispatchEventDropdownToggle();
this.resizeObserver.observe(this.trigger);
}
}

Expand Down Expand Up @@ -439,6 +443,20 @@ export class AuroDropdown extends LitElement {
}
}

/**
* Internal method to set up the resize observer. When an element is resized, we update
* the popper instance.
* @private
* @return {void}
*/
setUpResizeObserver() {
if ('ResizeObserver' in window) {
this.resizeObserver = new ResizeObserver(() => {
this.popper.triggerUpdate();
});
}
}

// function that renders the HTML and CSS into the scope of the component
render() {
return html`
Expand Down

0 comments on commit bac19b1

Please sign in to comment.