Skip to content

Commit

Permalink
feat: expose global recomputeAllPoppers helper (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu authored Jan 17, 2024
1 parent 004841e commit 1d9953d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ import { hideAllPoppers } from 'floating-vue'
hideAllPoppers()
```

### `recomputeAllPoppers`

Recompute the position of all shown poppers.

```js
import { recomputeAllPoppers } from 'floating-vue'

recomputeAllPoppers()
```

This function is automatically called when the window is resized.

### `createTooltip`

`createTooltip(el, valueOrOptions, directiveModifiers)` creates a tooltip on a given element.
Expand Down
4 changes: 2 additions & 2 deletions packages/floating-vue/src/components/Popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
} else {
window.addEventListener('mousedown', handleGlobalClose, true)
}
window.addEventListener('resize', computePositionAllShownPoppers)
window.addEventListener('resize', recomputeAllPoppers)
}

function handleGlobalClose (event: PopperEvent, touch = false) {
Expand Down Expand Up @@ -1117,7 +1117,7 @@ function getAutoHideResult (popper: PopperInstance, event: Event) {
return popper.autoHide
}

function computePositionAllShownPoppers () {
export function recomputeAllPoppers () {
for (let i = 0; i < shownPoppers.length; i++) {
const popper = shownPoppers[i]
popper.$_computePosition()
Expand Down
2 changes: 1 addition & 1 deletion packages/floating-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const ThemeClass = PrivateThemeClass
export const Tooltip = PrivateTooltip
export const TooltipDirective = PrivateTooltipDirective
// Utils
export { hideAllPoppers } from './components/Popper'
export { hideAllPoppers, recomputeAllPoppers } from './components/Popper'
export * from './util/events'
export { placements } from './util/popper'
export type { Placement } from './util/popper'
Expand Down

0 comments on commit 1d9953d

Please sign in to comment.