Skip to content

Commit f6b51e0

Browse files
saloevjacobmllr95
andauthored
fix(v-tooltip, v-popover): render data-* attributes on root components (closes #5836) (#5882)
* fix(v-tooltip, v-popover): render data-* attributes on root components * Delete package-lock.json * Remove TBD's * Attribute inheritance improvents * Update popover.spec.js Co-authored-by: Jacob Müller <jacob.mueller.elz@gmail.com>
1 parent daea0e5 commit f6b51e0

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

src/components/form-datepicker/form-datepicker.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ describe('form-date', () => {
182182
await waitNT(wrapper.vm)
183183
await waitRAF()
184184

185-
// TBD
186-
187185
wrapper.destroy()
188186
})
189187

src/components/popover/popover.spec.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ const App = {
3232
h(
3333
BPopover,
3434
{
35-
attrs: { id: 'bar' },
35+
attrs: {
36+
id: 'bar',
37+
'data-foo': 'bar'
38+
},
3639
props: {
3740
target: 'foo',
3841
triggers: this.triggers,
@@ -156,20 +159,22 @@ describe('b-popover', () => {
156159
expect($button.attributes('id')).toEqual('foo')
157160
expect($button.attributes('data-original-title')).not.toBeDefined()
158161
// ID of the tooltip that will be in the body
159-
const adb = $button.attributes('aria-describedby')
162+
const $adb = $button.attributes('aria-describedby')
160163

161164
// <b-popover> wrapper
162165
const $tipHolder = wrapper.findComponent(BPopover)
163166
expect($tipHolder.exists()).toBe(true)
164167
expect($tipHolder.element.nodeType).toEqual(Node.COMMENT_NODE)
165168

166169
// Find the popover element in the document
167-
const tip = document.getElementById(adb)
168-
expect(tip).not.toBe(null)
169-
expect(tip).toBeInstanceOf(HTMLElement)
170-
expect(tip.tagName).toEqual('DIV')
171-
expect(tip.classList.contains('popover')).toBe(true)
172-
expect(tip.classList.contains('b-popover')).toBe(true)
170+
const $tip = document.getElementById($adb)
171+
expect($tip).not.toBe(null)
172+
expect($tip).toBeInstanceOf(HTMLElement)
173+
expect($tip.tagName).toEqual('DIV')
174+
expect($tip.getAttribute('id')).toEqual('bar')
175+
expect($tip.getAttribute('data-foo')).toEqual('bar')
176+
expect($tip.classList.contains('popover')).toBe(true)
177+
expect($tip.classList.contains('b-popover')).toBe(true)
173178

174179
// Hide the Popover
175180
await wrapper.setProps({
@@ -184,8 +189,8 @@ describe('b-popover', () => {
184189
expect($button.attributes('aria-describedby')).not.toBeDefined()
185190

186191
// Popover element should not be in the document
187-
expect(document.body.contains(tip)).toBe(false)
188-
expect(document.getElementById(adb)).toBe(null)
192+
expect(document.body.contains($tip)).toBe(false)
193+
expect(document.getElementById($adb)).toBe(null)
189194

190195
wrapper.destroy()
191196
})

src/components/tooltip/helpers/bv-popper.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// Templates are only instantiated when shown, and destroyed when hidden
66
//
77

8+
import Popper from 'popper.js'
89
import { NAME_POPPER } from '../../../constants/components'
910
import Vue from '../../../utils/vue'
10-
import Popper from 'popper.js'
11+
import { BVTransition } from '../../../utils/bv-transition'
1112
import { getCS, requestAF, select } from '../../../utils/dom'
1213
import { toFloat } from '../../../utils/number'
1314
import { HTMLElement, SVGElement } from '../../../utils/safe-types'
14-
import { BVTransition } from '../../../utils/bv-transition'
1515

1616
const AttachmentMap = {
1717
AUTO: 'auto',
@@ -95,12 +95,12 @@ export const BVPopper = /*#__PURE__*/ Vue.extend({
9595
},
9696
computed: {
9797
/* istanbul ignore next */
98-
templateType() /* istanbul ignore next */ {
98+
templateType() {
9999
// Overridden by template component
100100
return 'unknown'
101101
},
102102
popperConfig() {
103-
const placement = this.placement
103+
const { placement } = this
104104
return {
105105
placement: this.getAttachment(placement),
106106
modifiers: {
@@ -157,9 +157,6 @@ export const BVPopper = /*#__PURE__*/ Vue.extend({
157157
// as our propsData is added after `new Template({...})`
158158
this.attachment = this.getAttachment(this.placement)
159159
},
160-
mounted() {
161-
// TBD
162-
},
163160
updated() {
164161
// Update popper if needed
165162
// TODO: Should this be a watcher on `this.popperConfig` instead?

src/components/tooltip/helpers/bv-tooltip-template.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ export const BVTooltipTemplate = /*#__PURE__*/ Vue.extend({
5151
},
5252
templateAttributes() {
5353
return {
54+
// Apply attributes from root tooltip component
55+
...this.$parent.$parent.$attrs,
56+
5457
id: this.id,
5558
role: 'tooltip',
5659
tabindex: '-1',
60+
5761
// Add the scoped style data attribute to the template root element
5862
...this.scopedStyleAttrs
5963
}

src/components/tooltip/helpers/bv-tooltip.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ const templateData = {
110110
// @vue/component
111111
export const BVTooltip = /*#__PURE__*/ Vue.extend({
112112
name: NAME_TOOLTIP_HELPER,
113-
props: {
114-
// None
115-
},
116113
data() {
117114
return {
118115
// BTooltip/BPopover/VBTooltip/VBPopover will update this data

src/components/tooltip/tooltip.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { BVTooltip } from './helpers/bv-tooltip'
1010
// @vue/component
1111
export const BTooltip = /*#__PURE__*/ Vue.extend({
1212
name: NAME_TOOLTIP,
13+
inheritAttrs: false,
1314
props: {
1415
title: {
1516
type: String

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy