Skip to content
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

Fix a11y in header button #1833

Merged
merged 12 commits into from
Mar 23, 2025
4 changes: 2 additions & 2 deletions _includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@
</ul>
</div>
<div class="header-right">
<div id="theme-icon-container" class="theme-toggle default-theme" title="toggle darkmode">
<button id="theme-toggle" type="button" class="theme-btn" title="change theme">
<i class="fa fa-moon-o fa-2x hidden-dark"></i>
<span class="sun-icon hidden-light"></span>
</div>
</button>
{% include language-picker.html %}
{% include language-picker-mobile.html %}
</div>
Expand Down
48 changes: 21 additions & 27 deletions _includes/language-picker.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
<div id="navbar">
<ul id="navmenu">
{% assign url_parts = page.url | split: '/' %}

{% assign url_remainder = url_parts | slice: 2, url_parts.size | join: '/' %}

<li class="submenu">
<div id="current-lang" class="current-lang"></div>
<div id="languageData"
data-languages='{{ site.data.languages | jsonify }}'
style="display:none;">
</div>
<ul class="submenu-content">
{% for lang in site.data.languages %}
<li>
<a href="/{{ lang.code }}/{{ url_remainder }}">
{% if lang.code | to_s == current_lang | to_s %}
<strong>{{ lang.name }}</strong>
{% else %}
{{ lang.name }}
{% endif %}
</a>
</li>
{% endfor %}
</ul>
</li>
</ul>
<div class="desktop-lang-switcher">
{% assign url_parts = page.url | split: '/' %}
{% assign url_remainder = url_parts | slice: 2, url_parts.size | join: '/' %}
{% assign current_lang = page.lang %}
<button class="lang-btn" type="button" aria-haspopup="menu" aria-label="Change language">
<span id="current-lang"></span>
</button>
<ul class="lang-list submenu-content" aria-labelledby="current-lang" >
{% for lang in site.data.languages %}
<li>
<a href="/{{ lang.code }}/{{ url_remainder }}">
{% if lang.code == current_lang %}
<strong>{{ lang.name }}</strong>
{% else %}
{{ lang.name }}
{% endif %}
</a>
</li>
{% endfor %}
</ul>
<div id="languageData" data-languages='{{ site.data.languages | jsonify }}' style="display:none;"></div>
</div>
2 changes: 1 addition & 1 deletion css/langs/ko.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* For image callouts in writing-middleware.md */

@import url('../fonts/ko/Pretendard.css');
@import url('../../fonts/ko/Pretendard.css');

html, body {font-family: Pretendard, Arial, sans-serif;}

Expand Down
2 changes: 1 addition & 1 deletion css/langs/th.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@font-face {
font-family: 'TH SarabunNew';
src: url("../fonts/th/THSarabunNew.woff")
src: url("../../fonts/th/THSarabunNew.woff")
}

#description .description {
Expand Down
86 changes: 79 additions & 7 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,84 @@ footer {
font-size: 20px;
}

/* navigation */
#theme-icon-container {
/* theme and lang btn */
button.theme-btn,
button.lang-btn {
cursor: pointer;
appearance: none;
background-color: inherit;
border: 0;
}

button.lang-btn {
color: var(--card-fg);
padding: 0.2rem;
font-size: inherit;
display: flex;
justify-content: center;
align-items: center;
gap: 1rem;

&::after {
content: "";
display: block;
width: 0.8em;
height: 0.5em;
background-color: var(--card-fg);
clip-path: polygon(100% 0%, 0 0%, 50% 100%);
cursor: pointer;
pointer-events: none;
transition: transform 0.2s ease-in-out;
}
}

div.desktop-lang-switcher {
position: relative;
> button.lang-btn {
&:is(:focus, :hover) {
& + ul {
display: block;
opacity: 1;
visibility: visible;
}
}
}
/* enable lang list tabbing on keyboard focus */
&:focus-within .lang-list {
display: block;
opacity: 1;
visibility: visible;
}

> ul.lang-list {
display: none;
opacity: 0;
position: absolute;
list-style: none;
visibility: hidden;
&:is(:hover, :focus) {
display: block;
opacity: 1;
visibility: visible;
}
li a {
display: block;
padding: 5px 20px 5px 20px;
text-decoration: none;
color: var(--card-fg);
&:is(:hover, :focus) {
background: var(--hover-bg);
}
}
}

/* rotate arrow */
&:is(:hover,:focus-within) button.lang-btn::after {
transform: rotate(180deg);
}
}

/* navigation */
#navbar {
line-height: 30px;
display: flex;
Expand Down Expand Up @@ -1391,6 +1464,10 @@ blockquote {
padding-inline: 32px;
}

.desktop-lang-switcher {
display: none;
}

#mobile-menu {
display: block;
}
Expand Down Expand Up @@ -1511,9 +1588,4 @@ blockquote {
.submenu-content li {
border-bottom: 1px solid var(--border);
}

#theme-icon-container{
z-index: 10000;
}

}
6 changes: 3 additions & 3 deletions js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const themeWatcher = watchColorSchemeChange((colorScheme) => {
if (!hasLocalStorage()) {
document?.addEventListener('DOMContentLoaded', () => {
// remove icon - toggle not supported
document.querySelector('#theme-icon-container').remove()
toggleSystemTheme(colorScheme)
document.querySelector('#theme-toggle').remove()
setTheme(colorScheme);
})
} else {
// user's PS system theme settings
Expand Down Expand Up @@ -35,7 +35,7 @@ const themeWatcher = watchColorSchemeChange((colorScheme) => {
document.addEventListener('DOMContentLoaded', () => {

document
.querySelector('.theme-toggle')
.querySelector('#theme-toggle')
.addEventListener('click', toggleLocalStorageTheme)
})
}
Expand Down