server/assets/js/react/utils/popperjs.ts

17 lines
471 B
TypeScript
Raw Normal View History

2023-12-05 22:02:58 +00:00
import { type Modifier } from "@popperjs/core"
export const sameWidth: Partial<Modifier<any, any>> = {
name: "sameWidth",
phase: "beforeWrite",
enabled: true,
requires: ["computeStyles"],
fn: ({ state }) => {
state.styles.popper.width = `${state.rects.reference.width}px`
},
effect: ({ state }) => {
if ("offsetWidth" in state.elements.reference) {
state.elements.popper.style.width = `${state.elements.reference.offsetWidth}px`
}
},
}