MCPcopy Create free account
hub / github.com/testing-library/user-event / getLabelDescr

Function getLabelDescr

src/utils/pointer/cssPointerEvents.ts:121–152  ·  view source on GitHub ↗
(element: Element)

Source from the content-addressed store, hash-verified

119}
120
121function getLabelDescr(element: Element) {
122 let label: string | undefined | null
123 if (element.hasAttribute('aria-label')) {
124 label = element.getAttribute('aria-label') as string
125 } else if (element.hasAttribute('aria-labelledby')) {
126 label = element.ownerDocument
127 .getElementById(element.getAttribute('aria-labelledby') as string)
128 ?.textContent?.trim()
129 } else if (
130 isElementType(element, [
131 'button',
132 'input',
133 'meter',
134 'output',
135 'progress',
136 'select',
137 'textarea',
138 ]) &&
139 element.labels?.length
140 ) {
141 label = Array.from(element.labels)
142 .map(el => el.textContent?.trim())
143 .join('|')
144 } else if (isElementType(element, 'button')) {
145 label = element.textContent?.trim()
146 }
147 label = label?.replace(/\n/g, ' ')
148 if (Number(label?.length) > 30) {
149 label = `${label?.substring(0, 29)}…`
150 }
151 return label ? `(label=${label})` : ''
152}
153
154// With the eslint rule and prettier the bitwise operation isn't nice to read
155function hasBitFlag(conf: number, flag: number) {

Callers 1

printTreeFunction · 0.85

Calls 1

isElementTypeFunction · 0.90

Tested by

no test coverage detected