-
Notifications
You must be signed in to change notification settings - Fork 0
Re-implement accessibility (at_rule colors, reduce-motion, prefers-contrast, forced-colors) #136
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
bf09bc5
d005e7a
4b27a5c
5f2abd3
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 |
|---|---|---|
| @@ -1,15 +1,55 @@ | ||
| export default { | ||
| mounted() { | ||
| document.body.style.setProperty("--q-primary", this.primary); | ||
| document.body.style.setProperty("--q-secondary", this.secondary); | ||
| document.body.style.setProperty("--q-accent", this.accent); | ||
| document.body.style.setProperty("--q-dark", this.dark); | ||
| document.body.style.setProperty("--q-dark-page", this.darkPage); | ||
| document.body.style.setProperty("--q-positive", this.positive); | ||
| document.body.style.setProperty("--q-negative", this.negative); | ||
| document.body.style.setProperty("--q-info", this.info); | ||
| document.body.style.setProperty("--q-warning", this.warning); | ||
| applyColors(this.customColors); | ||
| if (!this.atRule) { | ||
| document.body.style.setProperty("--q-primary", this.primary); | ||
| document.body.style.setProperty("--q-secondary", this.secondary); | ||
| document.body.style.setProperty("--q-accent", this.accent); | ||
| document.body.style.setProperty("--q-dark", this.dark); | ||
| document.body.style.setProperty("--q-dark-page", this.darkPage); | ||
| document.body.style.setProperty("--q-positive", this.positive); | ||
| document.body.style.setProperty("--q-negative", this.negative); | ||
| document.body.style.setProperty("--q-info", this.info); | ||
| document.body.style.setProperty("--q-warning", this.warning); | ||
| applyColors(this.customColors); | ||
| return; | ||
| } | ||
| const colors = { | ||
| "--q-primary": this.primary, | ||
| "--q-secondary": this.secondary, | ||
| "--q-accent": this.accent, | ||
| "--q-dark": this.dark, | ||
| "--q-dark-page": this.darkPage, | ||
| "--q-positive": this.positive, | ||
| "--q-negative": this.negative, | ||
| "--q-info": this.info, | ||
| "--q-warning": this.warning, | ||
| }; | ||
| let css = Object.entries(colors) | ||
| .map(([k, v]) => ` body { ${k}: ${v} !important; }`) | ||
| .join("\n"); | ||
| for (const [color, value] of Object.entries(this.customColors || {})) { | ||
| const name = color.replaceAll("_", "-"); | ||
| const varName = "--q-" + name; | ||
| css += `\n body { ${varName}: ${value} !important; }`; | ||
| css += `\n .text-${name} { color: var(${varName}) !important; }`; | ||
| css += `\n .bg-${name} { background-color: var(${varName}) !important; }`; | ||
| } | ||
| // Clear any prior NiceGUI-added color styles so earlier plain `ui.colors(...)` calls | ||
| // don't bleed through globally when this scoped at-rule block takes over. | ||
| // Mirrors the `[data-nicegui-custom-colors]` cleanup pattern in `applyColors` (static/nicegui.js). | ||
| document.head | ||
| .querySelectorAll("[data-nicegui-custom-colors], [data-nicegui-scoped-colors]") | ||
| .forEach((el) => el.remove()); | ||
| for (const key of Object.keys(colors)) { | ||
| document.body.style.removeProperty(key); | ||
| } | ||
| this.styleEl = document.createElement("style"); | ||
| this.styleEl.dataset.niceguiScopedColors = ""; | ||
| this.styleEl.innerHTML = `${this.atRule} {\n${css}\n}`; | ||
| document.head.appendChild(this.styleEl); | ||
|
Comment on lines
+30
to
+49
|
||
| }, | ||
| unmounted() { | ||
| this.styleEl?.remove(); | ||
| }, | ||
| props: { | ||
| primary: String, | ||
|
|
@@ -21,6 +61,7 @@ export default { | |
| negative: String, | ||
| info: String, | ||
| warning: String, | ||
| atRule: String, | ||
| customColors: Object, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -342,3 +342,12 @@ h6.q-timeline__title { | |
| position: absolute; | ||
| right: 1.5em; | ||
| } | ||
| @media (prefers-reduced-motion: reduce) { | ||
| *, | ||
| *::before, | ||
| *::after { | ||
| transition: none !important; | ||
| animation: none !important; | ||
| scroll-behavior: auto !important; | ||
| } | ||
|
Comment on lines
+345
to
+352
|
||
| } | ||
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.
at_ruleis currently only covered by a test that verifies the media query branch can set the primary color, but it doesn't exercise custom colors inside an at-rule (i.e., scoped.text-<custom>/.bg-<custom>rules) or verify that custom color styles don’t leak outside the at-rule when previousui.colorscalls have injected global custom-color CSS. Adding tests for these behaviors would help prevent regressions in the new styling path.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.
Noted. The existing
test_at_rulecovers the core at-rule branch (scoped--q-primaryoverride applied to a button). Expanding coverage to custom-color scoping + leak-prevention is reasonable but, given Falko's limited review bandwidth, keeping the test surface minimal for this PR. Happy to add more in a follow-up if desired.