Skip to content

Commit 29c9d78

Browse files
committed
feat: add open popper classes on body
1 parent 0a39097 commit 29c9d78

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/floating-vue/src/components/Popper.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ import { placements } from '../util/popper'
1313
import { SHOW_EVENT_MAP, HIDE_EVENT_MAP } from '../util/events'
1414
import { removeFromArray } from '../util/lang'
1515
import { nextFrame } from '../util/frame'
16-
import { getDefaultConfig } from '../config'
16+
import { getDefaultConfig, getAllParentThemes } from '../config'
1717

1818
export type ComputePositionConfig = Parameters<typeof computePosition>[2]
1919

2020
const shownPoppers = []
2121
let hidingPopper = null
2222

23+
const shownPoppersByTheme: Record<string, any[]> = {}
24+
function getShownPoppersByTheme (theme: string) {
25+
let list = shownPoppersByTheme[theme]
26+
if (!list) {
27+
list = shownPoppersByTheme[theme] = []
28+
}
29+
return list
30+
}
31+
2332
let Element: any = function () {}
2433
if (typeof window !== 'undefined') {
2534
Element = window.Element
@@ -729,6 +738,11 @@ export default () => ({
729738
}
730739

731740
shownPoppers.push(this)
741+
document.body.classList.add('v-popper--some-open')
742+
for (const theme of getAllParentThemes(this.theme)) {
743+
getShownPoppersByTheme(theme).push(this)
744+
document.body.classList.add(`v-popper--some-open--${theme}`)
745+
}
732746

733747
this.$emit('apply-show')
734748

@@ -758,6 +772,16 @@ export default () => ({
758772

759773
this.skipTransition = skipTransition
760774
removeFromArray(shownPoppers, this)
775+
if (shownPoppers.length === 0) {
776+
document.body.classList.remove('v-popper--some-open')
777+
}
778+
for (const theme of getAllParentThemes(this.theme)) {
779+
const list = getShownPoppersByTheme(theme)
780+
removeFromArray(list, this)
781+
if (list.length === 0) {
782+
document.body.classList.remove(`v-popper--some-open--${theme}`)
783+
}
784+
}
761785

762786
if (hidingPopper === this) {
763787
hidingPopper = null

packages/floating-vue/src/config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,18 @@ export function getThemeClasses (theme: string): string[] {
117117
} while (themeConfig)
118118
return result.map(c => `v-popper--theme-${c}`)
119119
}
120+
121+
export function getAllParentThemes (theme: string): string[] {
122+
const result = [theme]
123+
let themeConfig = config.themes[theme] || {}
124+
do {
125+
// Support theme extend
126+
if (themeConfig.$extend) {
127+
result.push(themeConfig.$extend)
128+
themeConfig = config.themes[themeConfig.$extend] || {}
129+
} else {
130+
themeConfig = null
131+
}
132+
} while (themeConfig)
133+
return result
134+
}

0 commit comments

Comments
 (0)