FIX: wraps popper call in afterRender and uses createPopper (#10621)

Before this fix, popper was sometimes not applied.
This commit is contained in:
Joffrey JAFFEUX 2020-09-07 13:33:52 +02:00 committed by GitHub
parent 27751ca69f
commit 0b8e7d88fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 22 deletions

View File

@ -1,6 +1,8 @@
import I18n from "I18n";
import { createWidget } from "discourse/widgets/widget";
import hbs from "discourse/widgets/hbs-compiler";
import { schedule } from "@ember/runloop";
import { createPopper } from "@popperjs/core";
/*
@ -244,33 +246,34 @@ export const WidgetDropdownClass = {
didRenderWidget() {
if (this.state.opened) {
const dropdownHeader = document.querySelector(
`#${this.attrs.id} .widget-dropdown-header`
);
schedule("afterRender", () => {
const dropdownHeader = document.querySelector(
`#${this.attrs.id} .widget-dropdown-header`
);
if (!dropdownHeader) return;
if (!dropdownHeader) return;
const dropdownBody = document.querySelector(
`#${this.attrs.id} .widget-dropdown-body`
);
const dropdownBody = document.querySelector(
`#${this.attrs.id} .widget-dropdown-body`
);
if (!dropdownBody) return;
if (!dropdownBody) return;
/* global Popper:true */
this._popper = Popper.createPopper(dropdownHeader, dropdownBody, {
strategy: "fixed",
placement: "bottom-start",
modifiers: [
{
name: "preventOverflow",
},
{
name: "offset",
options: {
offset: [0, 5],
this._popper = createPopper(dropdownHeader, dropdownBody, {
strategy: "fixed",
placement: "bottom-start",
modifiers: [
{
name: "preventOverflow",
},
},
],
{
name: "offset",
options: {
offset: [0, 5],
},
},
],
});
});
}
},