Skip to content
Open
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
4 changes: 4 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
## 2024-07-10 - prefers-reduced-motion 지원 μΆ”κ°€
**Learning:** μ‹œμŠ€ν…œ λ ˆλ²¨μ—μ„œ μ• λ‹ˆλ©”μ΄μ…˜ 쀄이기(prefers-reduced-motion)λ₯Ό μ„€μ •ν•œ μ‚¬μš©μžλ₯Ό μœ„ν•΄ κ³Όλ„ν•œ μ• λ‹ˆλ©”μ΄μ…˜κ³Ό λΆ€λ“œλŸ¬μš΄ μŠ€ν¬λ‘€μ„ λΉ„ν™œμ„±ν™”ν•˜λŠ” 것이 ν•„μš”ν•©λ‹ˆλ‹€. μ΄λ•Œ `0s` λŒ€μ‹  `0.01ms`λ₯Ό μ‚¬μš©ν•˜μ—¬ `transitionend`와 같은 λΈŒλΌμš°μ € μ΄λ²€νŠΈκ°€ μ •μƒμ μœΌλ‘œ λ°œμƒν•˜λ„λ‘ ν•΄μ•Ό μžλ°”μŠ€ν¬λ¦½νŠΈ 콜백이 λ©ˆμΆ”λŠ”(hanging) 문제λ₯Ό λ°©μ§€ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
**Action:** 항상 `styles.css` ν•˜λ‹¨μ— `prefers-reduced-motion: reduce` λ―Έλ””μ–΄ 쿼리λ₯Ό μΆ”κ°€ν•˜μ—¬ λͺ¨λ“  μš”μ†Œμ˜ `animation-duration`κ³Ό `transition-duration`을 `0.01ms`둜 μ„€μ •ν•˜κ³  `scroll-behavior: auto`λ₯Ό μ μš©ν•©λ‹ˆλ‹€.

## 2024-07-17 - Roving tabindex and Keyboard Navigation for Tabs
**Learning:** ARIA tablists require roving `tabindex` and arrow key navigation for proper keyboard accessibility. Without it, users have to tab through every single tab to get to the panels, which is inefficient.
**Action:** When creating custom tabs using ARIA `role="tablist"` and `role="tab"`, ensure only the selected tab is in the natural tab order (`tabindex="0"`), while others are removed (`tabindex="-1"`). Handle `ArrowLeft` and `ArrowRight` to switch focus and selection simultaneously.
8 changes: 4 additions & 4 deletions components/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ <h2>Badge &amp; Tag</h2>
<h2>Tabs</h2>
<p class="src">.krds-tabs Β· Figma Layout/Tabs 59:11</p>
<div class="krds-tabs">
<div class="krds-tabs__list" role="tablist">
<button class="krds-tab" role="tab" aria-selected="true" aria-controls="tp1" id="t1">κ°œμš”</button>
<button class="krds-tab" role="tab" aria-selected="false" aria-controls="tp2" id="t2">κ·Όκ±°</button>
<button class="krds-tab" role="tab" aria-selected="false" aria-controls="tp3" id="t3">μ°Έκ³ </button>
<div class="krds-tabs__list" role="tablist" aria-label="상세 정보">
<button class="krds-tab" role="tab" aria-selected="true" aria-controls="tp1" id="t1" tabindex="0">κ°œμš”</button>
<button class="krds-tab" role="tab" aria-selected="false" aria-controls="tp2" id="t2" tabindex="-1">κ·Όκ±°</button>
<button class="krds-tab" role="tab" aria-selected="false" aria-controls="tp3" id="t3" tabindex="-1">μ°Έκ³ </button>
</div>
<div class="krds-tabpanel" role="tabpanel" id="tp1" aria-labelledby="t1">κ°œμš” νŒ¨λ„ λ‚΄μš©μž…λ‹ˆλ‹€.</div>
<div class="krds-tabpanel" role="tabpanel" id="tp2" aria-labelledby="t2" hidden>κ·Όκ±° νŒ¨λ„ λ‚΄μš©μž…λ‹ˆλ‹€.</div>
Expand Down
28 changes: 21 additions & 7 deletions components/krds-gallery.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
// Tabs: minimal roving behavior. ponytail: native buttons + aria, no framework.
document.querySelectorAll(".krds-tabs").forEach((tabs) => {
const tabList = [...tabs.querySelectorAll('[role="tab"]')];
tabList.forEach((tab) => {
tab.addEventListener("click", () => {
tabList.forEach((t) => {
const sel = t === tab;
t.setAttribute("aria-selected", sel);
document.getElementById(t.getAttribute("aria-controls")).hidden = !sel;
});

const selectTab = (tab) => {
tabList.forEach((t) => {
const sel = t === tab;
t.setAttribute("aria-selected", sel);
t.setAttribute("tabindex", sel ? "0" : "-1");
document.getElementById(t.getAttribute("aria-controls")).hidden = !sel;
});
tab.focus();
};

tabList.forEach((tab, index) => {
tab.addEventListener("click", () => selectTab(tab));

tab.addEventListener("keydown", (e) => {
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
e.preventDefault();
const direction = e.key === "ArrowRight" ? 1 : -1;
const newIndex = (index + direction + tabList.length) % tabList.length;
selectTab(tabList[newIndex]);
}
});
});
});
Expand Down
Loading