Skip to content

Commit

Permalink
Use buttonface for UA <button> background color (#1472)
Browse files Browse the repository at this point in the history
* Use  for UA  background color

* Set up button background color where needed
  • Loading branch information
Jym77 authored Sep 26, 2023
1 parent ff127a0 commit 0337ca8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/stupid-lies-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@siteimprove/alfa-cascade": patch
---

**Changed:** `<button>`'s `background-color` now defaults to `buttonface`.

`<button>` elements default `background-color` is somewhat different between user-agents. Rather than picking one, we use the system `buttonface` color instead. This notably opens way to handle it with a branched value, possibly also detecting whether we are in forced colors mode.
10 changes: 9 additions & 1 deletion packages/alfa-cascade/src/user-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,18 @@ export const UserAgent = h.sheet([

h.rule.style("textarea", { whiteSpace: "pre-wrap" }),

// <button> element defaults applied consistently by browsers.
h.rule.style("button", {
// <button> element defaults applied consistently by browsers.
fontStyle: "normal",
fontWeight: "400",
// <button> colors differ between browsers, additionally they can be
// overwritten by OS settings which we do not really have access to (although
// forced-color media query could help), so we default to the system color.
// as of 21.09.23, Chrome uses rgb(240, 240, 240) but Firefox uses
// rgb(233, 233, 233).
backgroundColor: "buttonface",
// color seems to rather consistently defaults to black, which is the default.
// color: "buttontext",
}),

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-rules/test/sia-dr66/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ test("evaluate() passes text nodes in widgets with good contrast", async (t) =>

const document = h.document([
<html>
<button>{target}</button>
<button style={{ backgroundColor: "white" }}>{target}</button>
</html>,
]);

Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-rules/test/sia-dr69/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ test("evaluate() passes text nodes in widgets with good contrast", async (t) =>

const document = h.document([
<html>
<button>{target}</button>
<button style={{ backgroundColor: "white" }}>{target}</button>
</html>,
]);

Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-rules/test/sia-r66/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ test("evaluate() passes text nodes in widgets with good contrast", async (t) =>

const document = h.document([
<html>
<button>{target}</button>
<button style={{ backgroundColor: "white" }}>{target}</button>
</html>,
]);

Expand Down
2 changes: 1 addition & 1 deletion packages/alfa-rules/test/sia-r69/rule.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ test("evaluate() passes text nodes in widgets with good contrast", async (t) =>

const document = h.document([
<html>
<button>{target}</button>
<button style={{ backgroundColor: "white" }}>{target}</button>
</html>,
]);

Expand Down

0 comments on commit 0337ca8

Please sign in to comment.