Skip to content

docs(popovers, tooltips): add info about focus only trigger and cross platform behaviour #4767

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 9 commits into from
Feb 14, 2020
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
30 changes: 28 additions & 2 deletions src/components/popover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,37 @@ If a popover has more than one trigger, then all triggers must be cleared before
close. I.e. if a popover has the trigger `focus click`, and it was opened by `focus`, and the user
then clicks the trigger element, they must click it again **and** move focus to close the popover.

### Caveats with `focus` trigger on `<button>` elements

For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
`tabindex="0"` attribute.

The following will generate an `<a>` that looks like a button:

```html
<b-button
href="#"
tabindex="0"
v-b-popover.focus="'Popover content'"
title="Popover title"
>
Link button with popover directive
</b-button>

<b-button id="link-button" href="#" tabindex="0">
Link button with popover component
</b-button>
<b-popover target="link-button" title="Popover title" triggers="focus">
Popover content
</b-popover>
```

### Dismiss on next click (self-dismissing)

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

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

```html
<div class="text-center">
<b-button id="popover-button-variant">Button</b-button>
<b-button id="popover-button-variant" href="#" tabindex="0">Button</b-button>
<b-popover target="popover-button-variant" variant="danger" triggers="focus">
<template v-slot:title>Danger!</template>
Danger variant popover
Expand Down
26 changes: 26 additions & 0 deletions src/components/tooltip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ If a tooltip has more than one trigger, then all triggers must be cleared before
close. I.e. if a tooltip has the trigger `focus click`, and it was opened by `focus`, and the user
then clicks the trigger element, they must click it again **and** move focus to close the tooltip.

### Caveats with `focus` trigger on `<button>` elements

For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
`tabindex="0"` attribute.

The following will generate an `<a>` that looks like a button:

```html
<b-button
href="#"
tabindex="0"
v-b-tooltip.focus
title="Tooltip title"
>
Link button with tooltip directive
</b-button>

<b-button id="link-button" href="#" tabindex="0">
Link button with tooltip component
</b-button>
<b-tooltip target="link-button" title="Tooltip title" triggers="focus">
Tooltip title
</b-tooltip>
```

### Making tooltips work for keyboard and assistive technology users

You should only add tooltips to HTML elements that are traditionally keyboard-focusable and
Expand Down
19 changes: 19 additions & 0 deletions src/directives/popover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@ assistive technologies currently do not announce the popover in this situation.
Additionally, do not rely solely on `hover` as the trigger for your popover, as this will make your
popovers _impossible to trigger for keyboard-only users_.

### Caveats with `focus` trigger on `<button>` elements

For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
`tabindex="0"` attribute.

The following will generate an `<a>` that looks like a button:

```html
<b-button
href="#"
tabindex="0"
v-b-popover.focus="'Popover content'"
title="Popover title"
>
Link button with popover directive
</b-button>
```

### Dismiss on next click (self dismissing)

Use the `focus` trigger by itself to dismiss popovers on the next click that the user makes. `focus`
Expand Down
19 changes: 19 additions & 0 deletions src/directives/tooltip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ override the `pointer-events` on the disabled element.
<!-- disabled-trigger-element.vue -->
```

### Caveats with `focus` trigger on `<button>` elements

For proper cross-browser and cross-platform behavior when using only the `focus` trigger, you must
use an element that renders the `<a>` tag, not the `<button>` tag, and you also must include a
`tabindex="0"` attribute.

The following will generate an `<a>` that looks like a button:

```html
<b-button
href="#"
tabindex="0"
v-b-tooltip.focus
title="Tooltip title"
>
Link button with tooltip directive
</b-button>
```

### Dismiss on next click

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