Skip to content

Commit

Permalink
fix(retarget): do not unconditionally retarget to enclosing label (mi…
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Jan 7, 2025
1 parent 9514f0f commit 7923d35
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ export class InjectedScript {
if (!element.matches('a, input, textarea, button, select, [role=link], [role=button], [role=checkbox], [role=radio]') &&
!(element as any).isContentEditable) {
// Go up to the label that might be connected to the input/textarea.
element = element.closest('label') || element;
const enclosingLabel: HTMLLabelElement | null = element.closest('label');
if (enclosingLabel && enclosingLabel.control)
element = enclosingLabel.control;
}
if (element.nodeName === 'LABEL')
element = (element as HTMLLabelElement).control || element;
}
return element;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/page/retarget.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ it('enabled/disabled retargeting', async ({ page, asset }) => {
{ dom: domInButton(`<input id=target>`), enabled: true, locator: 'input' },
{ dom: domInLink(`<input id=target>`), enabled: true, locator: 'input' },
{ dom: domInButton(`<input id=target>`, { disabled: true }), enabled: true, locator: 'input' },
{ dom: domInLabel(`<li role=menuitem id=target aria-disabled=false></li>`), enabled: true, locator: 'li' },

{ dom: domInLabel(`<input id=target disabled>`), enabled: false, locator: 'label' },
{ dom: domLabelFor(`<input id=target disabled>`), enabled: false, locator: 'label' },
{ dom: domStandalone(`<input id=target disabled>`), enabled: false, locator: 'input' },
{ dom: domInButton(`<input id=target disabled>`), enabled: false, locator: 'input' },
{ dom: domInLink(`<input id=target disabled>`), enabled: false, locator: 'input' },
{ dom: domInButton(`<input id=target disabled>`, { disabled: true }), enabled: false, locator: 'input' },
{ dom: domInLabel(`<li role=menuitem id=target aria-disabled=true></li>`), enabled: false, locator: 'li' },
];
for (const { dom, enabled, locator } of cases) {
await it.step(`"${locator}" in "${dom}" should be enabled=${enabled}`, async () => {
Expand Down

0 comments on commit 7923d35

Please sign in to comment.