Skip to content
Open
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
23 changes: 21 additions & 2 deletions src/label-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,29 @@ function getRealLabels(element: Element) {
}

function isLabelable(element: Element) {
return (
if (
/BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA/.test(element.tagName) ||
(element.tagName === 'INPUT' && element.getAttribute('type') !== 'hidden')
)
) {
return true
}

// Support form-associated custom elements
if (
element.tagName.includes('-') &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
typeof (element as any).attachInternals === 'function'
) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const internals = (element as any).attachInternals()
return internals.formAssociated === true
} catch {
// Not a form-associated custom element or attachInternals not supported
}
}

return false
}

function getLabels(
Expand Down
Loading