oficina / estilo Public

desk: forced colours show selection and focus as separate marks

A selected segment's outline was overridden by nothing but also matched
the focus outline, so a focused selected segment showed no focus. Selection
is now a 2px border, focus an offset outline raised over its neighbours.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 65c3867ab4b565b8e93622e805e6018c37ad32e1 parent fac0d5e
2 files changed, +36 −2
  • desk/desk.css +10 −2
  • desk/desk_test.go +26 −0
diff --git a/desk/desk.css b/desk/desk.css
index de5cc80..4d97dd1 100644
--- a/desk/desk.css
+++ b/desk/desk.css
@@ -154,11 +154,19 @@
outline: 2px solid var(--rst-accent);
outline-offset: -2px;
}
-/* Forced colours drop the tint and the ring: keep a Highlight outline. */
+/* Forced colours drop the tint and the ring (a box-shadow). Selection
+ and focus each get their own mark, so a segment that is both shows
+ both: selection is a 2px border (Highlight), focus is an outline
+ 2px outside the segment, raised over its neighbours. */
@media (forced-colors: active) {
[estilo-seg-item][aria-pressed="true"],
[estilo-seg-item]:has(input:checked) {
+ border: 2px solid Highlight;
+ }
+ [estilo-seg-item]:focus-visible,
+ [estilo-seg-item]:has(input:focus-visible) {
+ z-index: 1;
outline: 2px solid Highlight;
- outline-offset: -2px;
+ outline-offset: 2px;
}
}
diff --git a/desk/desk_test.go b/desk/desk_test.go
index cb19761..00139ee 100644
--- a/desk/desk_test.go
+++ b/desk/desk_test.go
@@ -42,3 +42,29 @@ var pins = []string{
"box-shadow: inset 0 0 0 1px color-mix(in oklab, currentColor 45%, transparent)",
"outline: 2px solid Highlight",
}
+
+// In forced colours selection and focus must be separate marks, so a
+// segment that is both shows both: a border for selection, an offset
+// outline for focus, the focus rule after the selection rule.
+func TestForcedColoursSelectionAndFocusAreSeparate(t *testing.T) {
+ src := string(CSS())
+ i := strings.Index(src, "@media (forced-colors: active)")
+ if i < 0 {
+ t.Fatal("desk.css has no forced-colors block")
+ }
+ block := src[i:]
+ sel := strings.Index(block, "[estilo-seg-item][aria-pressed=\"true\"],\n [estilo-seg-item]:has(input:checked) {\n border: 2px solid Highlight;")
+ foc := strings.Index(block, "[estilo-seg-item]:has(input:focus-visible) {\n z-index: 1;\n outline: 2px solid Highlight;\n outline-offset: 2px;")
+ if sel < 0 {
+ t.Error("forced colours: selected segment (button and checked input) lost its border")
+ }
+ if foc < 0 {
+ t.Error("forced colours: focused segment (button and focused input) lost its offset outline")
+ }
+ if sel >= 0 && foc >= 0 && foc < sel {
+ t.Error("forced colours: the focus rule must come after the selection rule")
+ }
+ if strings.Contains(block, "outline-offset: -2px") {
+ t.Error("forced colours: an inset outline would hide focus on a selected segment")
+ }
+}