Skip to content

feat(config): Add option in config to set global tooltip and popover boundary #3229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/popover/popover.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Vue from '../../utils/vue'
import PopOver from '../../utils/popover.class'
import warn from '../../utils/warn'
import { getComponentConfig } from '../../utils/config'
import { HTMLElement } from '../../utils/safe-types'
import normalizeSlotMixin from '../../mixins/normalize-slot'
import toolpopMixin from '../../mixins/toolpop'

const NAME = 'BPopover'

export const props = {
title: {
type: String,
Expand All @@ -20,12 +24,22 @@ export const props = {
placement: {
type: String,
default: 'right'
},
boundary: {
// String: scrollParent, window, or viewport
// Element: element reference
type: [String, HTMLElement],
default: () => getComponentConfig(NAME, 'boundary')
},
boundaryPadding: {
type: Number,
default: () => getComponentConfig(NAME, 'boundaryPadding')
}
}

// @vue/component
export default Vue.extend({
name: 'BPopover',
name: NAME,
mixins: [toolpopMixin, normalizeSlotMixin],
props,
data() {
Expand Down
16 changes: 15 additions & 1 deletion src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import Vue from '../../utils/vue'
import ToolTip from '../../utils/tooltip.class'
import warn from '../../utils/warn'
import { getComponentConfig } from '../../utils/config'
import { HTMLElement } from '../../utils/safe-types'
import normalizeSlotMixin from '../../mixins/normalize-slot'
import toolpopMixin from '../../mixins/toolpop'

const NAME = 'BTooltip'

// @vue/component
export default Vue.extend({
name: 'BTooltip',
name: NAME,
mixins: [toolpopMixin, normalizeSlotMixin],
props: {
title: {
Expand All @@ -20,6 +24,16 @@ export default Vue.extend({
placement: {
type: String,
default: 'top'
},
boundary: {
// String: scrollParent, window, or viewport
// Element: element reference
type: [String, HTMLElement],
default: () => getComponentConfig(NAME, 'boundary')
},
boundaryPadding: {
type: Number,
default: () => getComponentConfig(NAME, 'boundaryPadding')
}
},
data() {
Expand Down
10 changes: 7 additions & 3 deletions src/directives/popover/popover.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Popper from 'popper.js'
import PopOver from '../../utils/popover.class'
import warn from '../../utils/warn'
import { getComponentConfig } from '../../utils/config'
import { isBrowser } from '../../utils/env'
import { isFunction, isObject, isString } from '../../utils/inspect'
import { keys } from '../../utils/object'
Expand All @@ -20,8 +21,11 @@ const validTriggers = {
// Arguments and modifiers take precedence over passed value config object
/* istanbul ignore next: not easy to test */
const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
// We start out with a blank config
let config = {}
// We start out with a basic config
let config = {
boundary: String(getComponentConfig('BPopover', 'boundary')),
boundaryPadding: parseInt(getComponentConfig('BPopover', 'boundaryPadding'), 10) || 0
}

// Process bindings.value
if (isString(bindings.value)) {
Expand Down Expand Up @@ -55,7 +59,7 @@ const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
) {
// placement of popover
config.placement = mod
} else if (/^(window|viewport)$/.test(mod)) {
} else if (/^(window|viewport|scrollParent)$/.test(mod)) {
// Boundary of popover
config.boundary = mod
} else if (/^d\d+$/.test(mod)) {
Expand Down
10 changes: 7 additions & 3 deletions src/directives/tooltip/tooltip.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Popper from 'popper.js'
import ToolTip from '../../utils/tooltip.class'
import warn from '../../utils/warn'
import { getComponentConfig } from '../../utils/config'
import { isBrowser } from '../../utils/env'
import { isFunction, isObject, isString } from '../../utils/inspect'
import { keys } from '../../utils/object'
Expand All @@ -20,8 +21,11 @@ const validTriggers = {
// Arguments and modifiers take precedence over passed value config object
/* istanbul ignore next: not easy to test */
const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
// We start out with a blank config
let config = {}
// We start out with a basic config
let config = {
boundary: String(getComponentConfig('BTooltip', 'boundary')),
boundaryPadding: parseInt(getComponentConfig('BTooltip', 'boundaryPadding'), 10) || 0
}

// Process bindings.value
if (isString(bindings.value)) {
Expand Down Expand Up @@ -55,7 +59,7 @@ const parseBindings = bindings => /* istanbul ignore next: not easy to test */ {
) {
// Placement of tooltip
config.placement = mod
} else if (/^(window|viewport)$/.test(mod)) {
} else if (/^(window|viewport|scrollParent)$/.test(mod)) {
// Boundary of tooltip
config.boundary = mod
} else if (/^d\d+$/.test(mod)) {
Expand Down
10 changes: 0 additions & 10 deletions src/mixins/toolpop.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ export default {
type: String,
default: null
},
boundary: {
// String: scrollParent, window, or viewport
// Element: element reference
type: [String, HTMLElement],
default: 'scrollParent'
},
boundaryPadding: {
type: Number,
default: 5
},
show: {
type: Boolean,
default: false
Expand Down
8 changes: 8 additions & 0 deletions src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ const DEFAULTS = {
ariaLive: 'polite',
ariaAtomic: 'true',
role: null
},
BTooltip: {
boundary: 'scrollParent',
boundaryPadding: 5
},
BPopover: {
boundary: 'scrollParent',
boundaryPadding: 5
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils/tooltip.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ const Defaults = {
container: false,
fallbackPlacement: 'flip',
callbacks: {},
boundary: 'scrollParent'
boundary: 'scrollParent',
boundaryPadding: 5
}

// Transition event names
Expand Down