Skip to content

Commit 7d3b019

Browse files
committed
Fix the sidebar button on iPhones
As per https://webkit.org/b/22261#c68, the Safari browser never gives buttons the focus. This breaks the expectation of git-scm.com's sidebar button that is shown on small screens: clicking on it will never open that sidebar and navigation is made harder than necessary by that. The solution, as per the hint at the incredibly helpful post at https://stackoverflow.com/questions/42758815/safari-focus-event-doesnt-work-on-button-element#53157834 is to turn the <button> into a <div tabindex="1">. That way, it works even on iPhones. With minor style adjustments, the button even looks the same as before! Reported-by: Toon Claes <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 8aa0d06 commit 7d3b019

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

assets/sass/sidebar.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ aside.sidebar.active {
4747
background-color: $black-3 !important;
4848
display: block;
4949
position: fixed;
50-
padding: 2rem 0.4rem;
50+
padding: 2rem 0rem;
5151
z-index: 1;
5252
border: none;
5353
left: 0;

layouts/partials/sidebar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{ $section := .Scratch.Get "section" }}
2-
<button class="sidebar-btn"></button>
2+
<div tabindex="1" class="sidebar-btn"></div>
33
<aside class="sidebar" id="sidebar">
44
<nav>
55
<ul>

playwright.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ module.exports = defineConfig({
5757
name: 'chrome',
5858
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
5959
},
60+
{
61+
name: 'iPhone',
62+
use: {
63+
...devices['iPhone 11'],
64+
},
65+
},
66+
6067

6168
/* Test against mobile viewports. */
6269
// {

tests/git-scm.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,19 @@ test('404', async ({ page }) => {
265265
// the usual navbar is shown
266266
await expect(page.getByRole('link', { name: 'Community' })).toBeVisible()
267267
})
268+
269+
test('sidebar', async ({ page }) => {
270+
await page.goto(`${url}community`);
271+
272+
test.skip(!await page.evaluate(() => matchMedia('(max-width: 940px)').matches),
273+
'not a small screen');
274+
275+
const sidebarButton = page.locator('.sidebar-btn');
276+
await expect(sidebarButton).toBeVisible();
277+
await sidebarButton.click();
278+
279+
const about = page.getByRole('link', { name: 'About', exact: true });
280+
await expect(about).toBeVisible();
281+
await about.click();
282+
await expect(page.getByRole('heading', { name: 'About - Branching and Merging' })).toBeVisible();
283+
});

0 commit comments

Comments
 (0)