Skip to content

Commit

Permalink
fix: support <label> for select and textarea (#143)
Browse files Browse the repository at this point in the history
* fix: support <label> for select and textarea

* Create clean-hounds-shop.md
  • Loading branch information
eps1lon committed Mar 15, 2020
1 parent 0dde2a1 commit bd41c2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-hounds-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fake-scope/fake-pkg": patch
---

fix: support `<label for>` for `<select>` and `<textarea>`
10 changes: 9 additions & 1 deletion sources/__tests__/accessible-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,15 @@ test.each([
// this would require a custom matcher
[`<button data-test>Click <em>me</em></option>`, "Click me"],
// byTitle('Hello, Dave!') => byRole('textbox', {name: 'Hello, Dave!'})
[`<input data-test title="Hello, Dave!" />`, "Hello, Dave!"]
[`<input data-test title="Hello, Dave!" />`, "Hello, Dave!"],
[
`<label for="select">A Select</label><select data-test id="select" />`,
"A Select"
],
[
`<label for="textarea">A TextArea</label><textarea data-test id="textarea" />`,
"A TextArea"
]
])(`test #%#`, testMarkup);

describe("prohibited naming", () => {
Expand Down
8 changes: 7 additions & 1 deletion sources/accessible-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,13 @@ export function computeAccessibleName(
}

function computeElementTextAlternative(node: Node): string | null {
if (!isHTMLInputElement(node)) {
if (
!(
isHTMLInputElement(node) ||
isHTMLSelectElement(node) ||
isHTMLTextAreaElement(node)
)
) {
return null;
}
const input = node;
Expand Down

0 comments on commit bd41c2d

Please sign in to comment.