-
Notifications
You must be signed in to change notification settings - Fork 0
🎨 Palette: [UX improvement] Enhancing accessibility and keyboard navigation #20
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ## 2024-03-21 - [Accessibility for Custom Components] | ||
| **Learning:** Custom interactive elements (e.g., product selection divs) must include role="button", tabindex="0", descriptive aria-label, and support for 'Enter' and 'Space' keydown events for full keyboard operability. | ||
| **Action:** Always check for non-semantic buttons and apply these attributes and listeners to ensure accessibility. | ||
|
|
||
| ## 2024-03-21 - [Dynamic Content Announcement] | ||
| **Learning:** Assign 'aria-live="polite"' to containers where dynamic content (like AI results) is injected to notify screen readers of updates. | ||
| **Action:** Implement aria-live on all async feedback containers. | ||
|
|
||
| ## 2024-03-21 - [Focus Visibility] | ||
| **Learning:** Implement a global ':focus-visible' style with a clear outline to ensure keyboard navigation visibility while maintaining aesthetics for mouse users. | ||
| **Action:** Ensure a gold outline with sufficient offset is applied globally to :focus-visible. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,9 +80,15 @@ class TryOnYouBunker { | |
| document.querySelectorAll('.product-item').forEach(item => { | ||
| const productId = item.getAttribute('onclick')?.match(/'([^']+)'/)?.[1]; | ||
| if (productId) { | ||
| item.addEventListener('click', (e) => { | ||
| const selectFn = (e) => { | ||
| e.preventDefault(); | ||
| this.selectGarment(productId, item); | ||
| }; | ||
| item.addEventListener('click', selectFn); | ||
| item.addEventListener('keydown', (e) => { | ||
| if (e.key === 'Enter' || e.key === ' ') { | ||
| selectFn(e); | ||
| } | ||
| }); | ||
| item.removeAttribute('onclick'); | ||
| } | ||
|
Comment on lines
81
to
94
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To accompany the change to using const productId = item.dataset.productId;
if (productId) {
const selectFn = (e) => {
e.preventDefault();
this.selectGarment(productId, item);
};
item.addEventListener('click', selectFn);
item.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
selectFn(e);
}
});
} |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better separation of concerns and more robust code, it's recommended to use
data-*attributes to store data, rather than embedding it within anonclickattribute. This makes your HTML cleaner and your JavaScript less fragile. This change should be made in conjunction with the suggested change injs/main.js.