Skip to content
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

Fix visibility of mono-line <select> #1696

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/famous-badgers-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@siteimprove/alfa-style": patch
---

**Fixed:** Mono-line `<select>` are again correctly considered as visible.
8 changes: 7 additions & 1 deletion packages/alfa-style/src/node/predicate/is-visible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ function isInvisible(
/**
* Elements that are *not* "replaced elements" but are nonetheless visible when
* empty
*
* @remarks
* * `<textarea>` always draw a box to input the text and thus are always visible
* even though they have no children.
* * Single line `<select>` do not show their children `<option>` but nonetheless
* show the text of the selected (or first) option, and thus are visible.
*/
const isVisibleWhenEmpty = hasName("textarea");
const isVisibleWhenEmpty = hasName("textarea", "select");

/**
* Does the element have set dimensions?
Expand Down
14 changes: 14 additions & 0 deletions packages/alfa-style/test/node/predicate/is-visible.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,17 @@ test("isVisible() returns false for `<option>` that are not shown, and their con
}
}
});

test("isVisible() returns true for single line `<select>`", (t) => {
const options = [<option>one</option>, <option>two</option>];

const select = <select>{options}</select>;

for (const node of options) {
// None of the `<option>` is visible, due to being a single line `<select>`
t(!isVisible(node));
}

// The `<select>` is nonetheless visible, showing the value of the first `<option>`.
t(isVisible(select));
});