Skip to content

Commit 1a5b60a

Browse files
fix(assertions): check disabled options inside labels directly (#43636)
Co-authored-by: microsoft-playwright-automation[bot] <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
1 parent 5481776 commit 1a5b60a

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎packages/injected/src/injectedScript.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ export class InjectedScript {
685685
element = element.closest('button, [role=button], [role=checkbox], [role=radio]') || element;
686686
}
687687
if (behavior === 'follow-label') {
688-
if (!element.matches('a, input, textarea, button, select, [role=link], [role=button], [role=checkbox], [role=radio]') &&
688+
if (!element.matches('a, input, textarea, button, select, option, optgroup, [role=link], [role=button], [role=checkbox], [role=radio]') &&
689689
!(element as any).isContentEditable) {
690690
// Go up to the label that might be connected to the input/textarea.
691691
const enclosingLabel: HTMLLabelElement | null = element.closest('label');

‎tests/page/retarget.spec.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const domStandalone = (dom: string) => dom;
101101
const domInButton = (dom: string, options?: Options) => `<button ${optionsToAttributes(options)}>Button ${dom}</button>`;
102102
const domInLink = (dom: string, options?: Options) => `<button ${optionsToAttributes(options)}>Button ${dom}</button>`;
103103

104-
it('RE-007 enabled/disabled retargeting', async ({ page, asset }) => {
104+
it('RE-007 enabled/disabled retargeting', { annotation: { type: 'issue', description: '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/microsoft/playwright/issues/43634' } }, async ({ page, asset }) => {
105105
const cases = [
106106
{ dom: domInLabel(`<input id=target>`), enabled: true, locator: 'label' },
107107
{ dom: domLabelFor(`<input id=target>`), enabled: true, locator: 'label' },
@@ -118,6 +118,8 @@ it('RE-007 enabled/disabled retargeting', async ({ page, asset }) => {
118118
{ dom: domInLink(`<input id=target disabled>`), enabled: false, locator: 'input' },
119119
{ dom: domInButton(`<input id=target disabled>`, { disabled: true }), enabled: false, locator: 'input' },
120120
{ dom: domInLabel(`<li role=menuitem id=target aria-disabled=true></li>`), enabled: false, locator: 'li' },
121+
{ dom: domInLabel(`<select><option disabled>Other employees</option><option>Alex</option></select>`), enabled: false, locator: 'option >> nth=0' },
122+
{ dom: domInLabel(`<select><optgroup disabled label="Other employees"><option>Alex</option></optgroup></select>`), enabled: false, locator: 'optgroup' },
121123
];
122124
for (const { dom, enabled, locator } of cases) {
123125
await it.step(`"${locator}" in "${dom}" should be enabled=${enabled}`, async () => {

0 commit comments

Comments
 (0)