-
Notifications
You must be signed in to change notification settings - Fork 456
Restore keyboard focus indicator on bare .btn buttons #14785
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
+136
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
456e129
Restore keyboard focus indicator on bare .btn buttons (#14774)
cwickham 92a59ef
Address review: unprefix nav selectors, gitignore the fixture
cwickham c607726
Merge branch 'main' into bare-btn-focus-indicator
cwickham 64805b6
Merge branch 'main' into bare-btn-focus-indicator
cwickham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| title: Code tools focus indicator | ||
| format: html | ||
| code-tools: true | ||
| --- | ||
|
|
||
| Regression test for #14774: the Code button is a bare Bootstrap `.btn` | ||
| (no `btn-*` variant class), so Bootstrap's `outline: 0` left it with no | ||
| keyboard focus indicator. Quarto restores the native ring with | ||
| `outline: revert`. | ||
|
|
||
| ```r | ||
| 1 + 1 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /.quarto/ | ||
| /_site/ | ||
|
|
||
| **/*.quarto_ipynb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| project: | ||
| type: website | ||
|
|
||
| website: | ||
| title: "bare-btn-focus" | ||
| search: | ||
| location: sidebar | ||
| navbar: | ||
| left: | ||
| - href: index.qmd | ||
| text: Home | ||
| sidebar: | ||
| style: floating | ||
| search: true | ||
| contents: | ||
| - index.qmd | ||
| - about.qmd | ||
|
|
||
| format: html | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| title: "About" | ||
| --- | ||
|
|
||
| Second page so the sidebar has more than one entry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| title: "Home" | ||
| --- | ||
|
|
||
| Regression test for #14774: below 992px the secondary nav shows the | ||
| sidebar toggle and sidebar search buttons. Both are bare Bootstrap | ||
| `.btn` elements and must keep a visible keyboard focus indicator. |
76 changes: 76 additions & 0 deletions
76
tests/integration/playwright/tests/html-focus-indicator-bare-btn.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { expect, Locator, Page, test } from "@playwright/test"; | ||
| import { getUrl } from "../src/utils"; | ||
|
|
||
| // Regression tests for #14774. Quarto emits three buttons that carry the | ||
| // Bootstrap `btn` class with no `btn-*` variant class: the code tools | ||
| // button, the sidebar toggle, and the sidebar search button. Bootstrap's | ||
| // .btn:focus-visible removes the native focus ring (outline: 0) and | ||
| // substitutes a box-shadow that only the variant classes define, so these | ||
| // buttons took keyboard focus with no visible indicator. Quarto restores | ||
| // the browser's native ring with `outline: revert`. | ||
|
|
||
| // Move focus with real Tab presses so the button matches :focus-visible — | ||
| // the fix only applies to keyboard focus, and programmatic locator.focus() | ||
| // does not reliably match :focus-visible. WebKit follows Safari's default | ||
| // of skipping buttons on Tab; Option+Tab visits every focusable element. | ||
| async function tabUntilFocused( | ||
| page: Page, | ||
| browserName: string, | ||
| target: Locator, | ||
| maxTabs = 25, | ||
| ): Promise<boolean> { | ||
| const tabKey = browserName === "webkit" ? "Alt+Tab" : "Tab"; | ||
|
cderv marked this conversation as resolved.
|
||
| for (let i = 0; i < maxTabs; i++) { | ||
| await page.keyboard.press(tabKey); | ||
| if (await target.evaluate((el) => el === document.activeElement)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| test("code tools button shows a focus indicator on keyboard focus", async ({ | ||
| page, | ||
| browserName, | ||
| }) => { | ||
| await page.goto(getUrl("html/code-tools-focus-indicator.html"), { | ||
| waitUntil: "load", | ||
| }); | ||
|
|
||
| const button = page.locator("button.code-tools-button"); | ||
| await expect(button).toBeVisible(); | ||
| expect(await tabUntilFocused(page, browserName, button)).toBe(true); | ||
|
|
||
| // outline: revert restores the user-agent ring (outline-style: auto in | ||
| // every engine); any non-none outline is a visible indicator. | ||
| await expect(button).not.toHaveCSS("outline-style", "none"); | ||
| }); | ||
|
|
||
| test.describe("website secondary nav buttons", () => { | ||
| // The secondary nav holding the sidebar toggle and sidebar search | ||
| // buttons only appears when the sidebar collapses, below the lg | ||
| // breakpoint (992px). | ||
| test.use({ viewport: { width: 500, height: 800 } }); | ||
|
|
||
| const buttons = [ | ||
| { name: "sidebar toggle", selector: "button.quarto-btn-toggle" }, | ||
| { name: "sidebar search", selector: "button.quarto-search-button" }, | ||
| ]; | ||
|
|
||
| for (const { name, selector } of buttons) { | ||
| test(`${name} button shows a focus indicator on keyboard focus`, async ({ | ||
| page, | ||
| browserName, | ||
| }) => { | ||
| await page.goto(getUrl("website/bare-btn-focus/_site/index.html"), { | ||
| waitUntil: "load", | ||
| }); | ||
|
|
||
| const button = page.locator(`.quarto-secondary-nav ${selector}`); | ||
| await expect(button).toBeVisible(); | ||
| expect(await tabUntilFocused(page, browserName, button)).toBe(true); | ||
|
|
||
| await expect(button).not.toHaveCSS("outline-style", "none"); | ||
| }); | ||
| } | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.