Skip to content

[Bug]: aria-labelledby and aria-describedby ignore IDs separated by a newline or a tab #43359

Closed

Description

Version

1.64.0

Steps to reproduce

import { test, expect } from '@playwright/test';

test('id reference lists separated by a newline or a tab', async ({ page }) => {
  await page.setContent(`
    <span id="first">Hello</span><span id="last">World</span>
    <span id="hint">Some hint</span><span id="err">Required</span>
    <button aria-labelledby="first\n  last">x</button>
    <input aria-label="Email" aria-describedby="hint\terr">
  `);
  await expect.soft(page.getByRole('button')).toHaveAccessibleName('Hello World');
  await expect.soft(page.getByRole('textbox')).toHaveAccessibleDescription('Some hint Required');
});

npx playwright test

Expected behavior

Both assertions pass. ID reference lists are separated by ASCII whitespace, so a newline or a tab between IDs works the same as a space. Chromium's own accessibility tree (Accessibility.getFullAXTree) reports the name Hello World for the button and the description Some hint Required for the textbox.

Actual behavior

Error: expect(locator).toHaveAccessibleName(expected) failed
Expected: "Hello World"
Received: "World"

Error: expect(locator).toHaveAccessibleDescription(expected) failed
Expected: "Some hint Required"
Received: ""

ariaSnapshot() shows - button "World": x, and getByRole('button', { name: 'Hello World' }) matches nothing. This happens with formatted HTML where a long aria-labelledby list is wrapped onto several lines.

Additional context

getIdRefs in packages/injected/src/roleUtils.ts splits the attribute with ref.split(' '). A token like first\n then matches no element and is dropped. The same helper is used for aria-labelledby, aria-describedby, aria-errormessage and aria-owns. ariaSnapshot.ts already splits aria-owns with /\s+/.

I'd like to send a PR that splits on whitespace instead, with an extra case in the native controls labelled-by test in tests/library/role-utils.spec.ts.

Environment

System:
  OS: Linux 6.18 Ubuntu 24.04.5 LTS 24.04.5 LTS (Noble Numbat)
  CPU: (4) x64 Intel(R) Xeon(R) Processor @ 2.80GHz
  Memory: 13.56 GB / 15.72 GB
Binaries:
  Node: 22.22.0
  npm: 10.9.4
npmPackages:
  @playwright/test: ^1.64.0 => 1.64.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions