Skip to content

Commit 4259595

Browse files
committed
feat: ariaId, closes #379
1 parent 39749a8 commit 4259595

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

docs-src/PageHome.vue

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
:placement="placement"
156156
:auto-hide="isAutoHiding"
157157
:disabled="!isEnabled"
158+
aria-id="test-popper-aria-id"
158159
open-class="is-open"
159160
>
160161
<button class="tooltip-target b3 popover-btn">Click me</button>

src/components/Popover.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ export default {
165165
type: [String, Array],
166166
default: () => directive.options.popover.defaultOpenClass,
167167
},
168+
169+
ariaId: {
170+
default: null,
171+
},
168172
},
169173
170174
data () {
@@ -182,7 +186,7 @@ export default {
182186
},
183187
184188
popoverId () {
185-
return `popover_${this.id}`
189+
return `popover_${this.ariaId != null ? this.ariaId : this.id}`
186190
},
187191
},
188192

src/lib/tooltip.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default class Tooltip {
5151
* [offset docs](https://popper.js.org/popper-documentation.html)
5252
* @param {Object} options.popperOptions={} - Popper options, will be passed directly to popper instance. For more information refer to Popper.js'
5353
* [options docs](https://popper.js.org/popper-documentation.html)
54+
* @param {string} [options.ariaId] Id used for accessibility
5455
* @return {Object} instance - The generated tooltip instance
5556
*/
5657
constructor (reference, options) {
@@ -221,7 +222,7 @@ export default class Tooltip {
221222
const tooltipNode = tooltipGenerator.childNodes[0]
222223

223224
// add unique ID to our tooltip (needed for accessibility reasons)
224-
tooltipNode.id = `tooltip_${Math.random().toString(36).substr(2, 10)}`
225+
tooltipNode.id = this.options.ariaId || `tooltip_${Math.random().toString(36).substr(2, 10)}`
225226

226227
// Initially hide the tooltip
227228
// The attribute will be switched in a next frame so

0 commit comments

Comments
 (0)