Skip to content
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

Container can accept a callback #810

Open
wants to merge 2 commits into
base: v-tooltip-3
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
npm-debug.log
coverage/
dist/
.idea/
6 changes: 5 additions & 1 deletion packages/v-tooltip/src/components/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default () => ({
},

container: {
type: [String, Object, Element, Boolean],
type: [String, Object, Element, Boolean, Function],
default () {
return getDefaultConfig(this.theme, 'container')
},
Expand Down Expand Up @@ -571,6 +571,10 @@ export default () => ({

$_ensureContainer () {
let container = this.container
// if container is a callback, resolve it
if (typeof container === 'function') {
container = container(this.$_targetNodes[0])
}
// if container is a query, get the relative element
if (typeof container === 'string') {
container = window.document.querySelector(container)
Expand Down
4 changes: 2 additions & 2 deletions packages/v-tooltip/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export const config = {
disabled: false,
// Default position offset [skidding, distance] (px)
offset: [0, 5],
// Default container where the tooltip will be appended
// Default container where the tooltip will be appended, can accept a callback that should return an element or a query selector
container: 'body',
// Element used to compute position and size boundaries
boundary: undefined,
// Skip delay & CSS transitions when another popper is shown, so that the popper appear to instanly move to the new position.
// Skip delay & CSS transitions when another popper is shown, so that the popper appear to instantly move to the new position.
instantMove: false,
// Auto destroy tooltip DOM nodes (ms)
disposeTimeout: 5000,
Expand Down