Skip to content

Commit 00e4fc9

Browse files
AlanRezendetmorehouse
authored andcommitted
feat(config): add option in config to set global tooltip and popover boundary (bootstrap-vue#3229)
1 parent 63c4361 commit 00e4fc9

File tree

7 files changed

+54
-19
lines changed

7 files changed

+54
-19
lines changed

src/components/popover/popover.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import Vue from '../../utils/vue'
22
import PopOver from '../../utils/popover.class'
33
import warn from '../../utils/warn'
4+
import { getComponentConfig } from '../../utils/config'
5+
import { HTMLElement } from '../../utils/safe-types'
46
import normalizeSlotMixin from '../../mixins/normalize-slot'
57
import toolpopMixin from '../../mixins/toolpop'
68

9+
const NAME = 'BPopover'
10+
711
export const props = {
812
title: {
913
type: String,
@@ -20,12 +24,22 @@ export const props = {
2024
placement: {
2125
type: String,
2226
default: 'right'
27+
},
28+
boundary: {
29+
// String: scrollParent, window, or viewport
30+
// Element: element reference
31+
type: [String, HTMLElement],
32+
default: () => getComponentConfig(NAME, 'boundary')
33+
},
34+
boundaryPadding: {
35+
type: Number,
36+
default: () => getComponentConfig(NAME, 'boundaryPadding')
2337
}
2438
}
2539

2640
// @vue/component
2741
export default Vue.extend({
28-
name: 'BPopover',
42+
name: NAME,
2943
mixins: [toolpopMixin, normalizeSlotMixin],
3044
props,
3145
data() {

src/components/tooltip/tooltip.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import Vue from '../../utils/vue'
22
import ToolTip from '../../utils/tooltip.class'
33
import warn from '../../utils/warn'
4+
import { getComponentConfig } from '../../utils/config'
5+
import { HTMLElement } from '../../utils/safe-types'
46
import normalizeSlotMixin from '../../mixins/normalize-slot'
57
import toolpopMixin from '../../mixins/toolpop'
68

9+
const NAME = 'BTooltip'
10+
711
// @vue/component
812
export default Vue.extend({
9-
name: 'BTooltip',
13+
name: NAME,
1014
mixins: [toolpopMixin, normalizeSlotMixin],
1115
props: {
1216
title: {
@@ -20,6 +24,16 @@ export default Vue.extend({
2024
placement: {
2125
type: String,
2226
default: 'top'
27+
},
28+
boundary: {
29+
// String: scrollParent, window, or viewport
30+
// Element: element reference
31+
type: [String, HTMLElement],
32+
default: () => getComponentConfig(NAME, 'boundary')
33+
},
34+
boundaryPadding: {
35+
type: Number,
36+
default: () => getComponentConfig(NAME, 'boundaryPadding')
2337
}
2438
},
2539
data() {

src/directives/popover/popover.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Popper from 'popper.js'
22
import PopOver from '../../utils/popover.class'
33
import warn from '../../utils/warn'
4+
import { getComponentConfig } from '../../utils/config'
45
import { isBrowser } from '../../utils/env'
56
import { isFunction, isObject, isString } from '../../utils/inspect'
67
import { keys } from '../../utils/object'
@@ -20,8 +21,11 @@ const validTriggers = {
2021
// Arguments and modifiers take precedence over passed value config object
2122
/* istanbul ignore next: not easy to test */
2223
const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
23-
// We start out with a blank config
24-
let config = {}
24+
// We start out with a basic config
25+
let config = {
26+
boundary: String(getComponentConfig('BPopover', 'boundary')),
27+
boundaryPadding: parseInt(getComponentConfig('BPopover', 'boundaryPadding'), 10) || 0
28+
}
2529

2630
// Process bindings.value
2731
if (isString(bindings.value)) {
@@ -55,7 +59,7 @@ const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
5559
) {
5660
// placement of popover
5761
config.placement = mod
58-
} else if (/^(window|viewport)$/.test(mod)) {
62+
} else if (/^(window|viewport|scrollParent)$/.test(mod)) {
5963
// Boundary of popover
6064
config.boundary = mod
6165
} else if (/^d\d+$/.test(mod)) {

src/directives/tooltip/tooltip.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Popper from 'popper.js'
22
import ToolTip from '../../utils/tooltip.class'
33
import warn from '../../utils/warn'
4+
import { getComponentConfig } from '../../utils/config'
45
import { isBrowser } from '../../utils/env'
56
import { isFunction, isObject, isString } from '../../utils/inspect'
67
import { keys } from '../../utils/object'
@@ -20,8 +21,11 @@ const validTriggers = {
2021
// Arguments and modifiers take precedence over passed value config object
2122
/* istanbul ignore next: not easy to test */
2223
const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
23-
// We start out with a blank config
24-
let config = {}
24+
// We start out with a basic config
25+
let config = {
26+
boundary: String(getComponentConfig('BTooltip', 'boundary')),
27+
boundaryPadding: parseInt(getComponentConfig('BTooltip', 'boundaryPadding'), 10) || 0
28+
}
2529

2630
// Process bindings.value
2731
if (isString(bindings.value)) {
@@ -55,7 +59,7 @@ const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
5559
) {
5660
// Placement of tooltip
5761
config.placement = mod
58-
} else if (/^(window|viewport)$/.test(mod)) {
62+
} else if (/^(window|viewport|scrollParent)$/.test(mod)) {
5963
// Boundary of tooltip
6064
config.boundary = mod
6165
} else if (/^d\d+$/.test(mod)) {

src/mixins/toolpop.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@ export default {
5959
type: String,
6060
default: null
6161
},
62-
boundary: {
63-
// String: scrollParent, window, or viewport
64-
// Element: element reference
65-
type: [String, HTMLElement],
66-
default: 'scrollParent'
67-
},
68-
boundaryPadding: {
69-
type: Number,
70-
default: 5
71-
},
7262
show: {
7363
type: Boolean,
7464
default: false

src/utils/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ const DEFAULTS = {
142142
ariaLive: 'polite',
143143
ariaAtomic: 'true',
144144
role: null
145+
},
146+
BTooltip: {
147+
boundary: 'scrollParent',
148+
boundaryPadding: 5
149+
},
150+
BPopover: {
151+
boundary: 'scrollParent',
152+
boundaryPadding: 5
145153
}
146154
}
147155

src/utils/tooltip.class.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ const Defaults = {
9595
container: false,
9696
fallbackPlacement: 'flip',
9797
callbacks: {},
98-
boundary: 'scrollParent'
98+
boundary: 'scrollParent',
99+
boundaryPadding: 5
99100
}
100101

101102
// Transition event names

0 commit comments

Comments
 (0)