Skip to content

Commit 97a65c2

Browse files
docs(popovers, tooltips): add info about focus only trigger and cross platform behaviour (bootstrap-vue#4767)
* docs(popovers, tooltips): add info about focus only trigger and cross platform behaviour * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md Co-authored-by: Jacob Müller <jacob.mueller.elz@gmail.com>
1 parent 968c957 commit 97a65c2

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

src/components/popover/README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,37 @@ If a popover has more than one trigger, then all triggers must be cleared before
160160
close. I.e. if a popover has the trigger `focus click`, and it was opened by `focus`, and the user
161161
then clicks the trigger element, they must click it again **and** move focus to close the popover.
162162

163+
### Caveats with `focus` trigger on `<button>` elements
164+
165+
For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
166+
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
167+
`tabindex="0"` attribute.
168+
169+
The following will generate an `<a>` that looks like a button:
170+
171+
```html
172+
<b-button
173+
href="#"
174+
tabindex="0"
175+
v-b-popover.focus="'Popover content'"
176+
title="Popover title"
177+
>
178+
Link button with popover directive
179+
</b-button>
180+
181+
<b-button id="link-button" href="#" tabindex="0">
182+
Link button with popover component
183+
</b-button>
184+
<b-popover target="link-button" title="Popover title" triggers="focus">
185+
Popover content
186+
</b-popover>
187+
```
188+
163189
### Dismiss on next click (self-dismissing)
164190

165191
Use the `focus` trigger by itself to dismiss popovers on the next click that the user makes. `focus`
166192
also makes the popover activate on both `focus` and `click` (as a click makes the element receive
167-
focus, assuming it is in the tab sequence of the page).
193+
focus on most browsers, assuming it is in the tab sequence of the page).
168194

169195
You can, however, specify your trigger as `click blur`, which will make only a click activate the
170196
popover, and either a click on the element, _or_ losing focus to another element or part of the
@@ -274,7 +300,7 @@ prop:
274300

275301
```html
276302
<div class="text-center">
277-
<b-button id="popover-button-variant">Button</b-button>
303+
<b-button id="popover-button-variant" href="#" tabindex="0">Button</b-button>
278304
<b-popover target="popover-button-variant" variant="danger" triggers="focus">
279305
<template v-slot:title>Danger!</template>
280306
Danger variant popover

src/components/tooltip/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,32 @@ If a tooltip has more than one trigger, then all triggers must be cleared before
106106
close. I.e. if a tooltip has the trigger `focus click`, and it was opened by `focus`, and the user
107107
then clicks the trigger element, they must click it again **and** move focus to close the tooltip.
108108

109+
### Caveats with `focus` trigger on `<button>` elements
110+
111+
For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
112+
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
113+
`tabindex="0"` attribute.
114+
115+
The following will generate an `<a>` that looks like a button:
116+
117+
```html
118+
<b-button
119+
href="#"
120+
tabindex="0"
121+
v-b-tooltip.focus
122+
title="Tooltip title"
123+
>
124+
Link button with tooltip directive
125+
</b-button>
126+
127+
<b-button id="link-button" href="#" tabindex="0">
128+
Link button with tooltip component
129+
</b-button>
130+
<b-tooltip target="link-button" title="Tooltip title" triggers="focus">
131+
Tooltip title
132+
</b-tooltip>
133+
```
134+
109135
### Making tooltips work for keyboard and assistive technology users
110136

111137
You should only add tooltips to HTML elements that are traditionally keyboard-focusable and

src/directives/popover/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ assistive technologies currently do not announce the popover in this situation.
215215
Additionally, do not rely solely on `hover` as the trigger for your popover, as this will make your
216216
popovers _impossible to trigger for keyboard-only users_.
217217

218+
### Caveats with `focus` trigger on `<button>` elements
219+
220+
For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
221+
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
222+
`tabindex="0"` attribute.
223+
224+
The following will generate an `<a>` that looks like a button:
225+
226+
```html
227+
<b-button
228+
href="#"
229+
tabindex="0"
230+
v-b-popover.focus="'Popover content'"
231+
title="Popover title"
232+
>
233+
Link button with popover directive
234+
</b-button>
235+
```
236+
218237
### Dismiss on next click (self dismissing)
219238

220239
Use the `focus` trigger by itself to dismiss popovers on the next click that the user makes. `focus`

src/directives/tooltip/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ override the `pointer-events` on the disabled element.
172172
<!-- disabled-trigger-element.vue -->
173173
```
174174

175+
### Caveats with `focus` trigger on `<button>` elements
176+
177+
For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
178+
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
179+
`tabindex="0"` attribute.
180+
181+
The following will generate an `<a>` that looks like a button:
182+
183+
```html
184+
<b-button
185+
href="#"
186+
tabindex="0"
187+
v-b-tooltip.focus
188+
title="Tooltip title"
189+
>
190+
Link button with tooltip directive
191+
</b-button>
192+
```
193+
175194
### Dismiss on next click
176195

177196
Use both `click` and `blur` if you would like a tooltip that opens only on click of the element, but

0 commit comments

Comments
 (0)