diff --git a/package.json b/package.json index 0b2584b8298c1e..56b2e641ad59c9 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,7 @@ "confusing-browser-globals": "^1.0.9", "cross-env": "^6.0.0", "danger": "^9.1.8", + "dom-accessibility-api": "^0.2.0", "dtslint": "^2.0.0", "enzyme": "^3.9.0", "enzyme-adapter-react-16": "^1.14.0", diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js index 6ffab05fc88368..457b1095add98f 100644 --- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js +++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.test.js @@ -119,9 +119,9 @@ describe('', () => { const buttons = getAllByRole('button'); expect(buttons).to.have.length(2); - // TODO: computeAccessibleName + expect(buttons[0]).to.have.accessibleName('Clear'); expect(buttons[0]).to.have.attribute('title', 'Clear'); - // TODO: computeAccessibleName + expect(buttons[1]).to.have.accessibleName('Open'); expect(buttons[1]).to.have.attribute('title', 'Open'); buttons.forEach(button => { expect(button, 'button is not in tab order').to.have.property('tabIndex', -1); @@ -160,9 +160,9 @@ describe('', () => { const buttons = getAllByRole('button'); expect(buttons).to.have.length(2); - // TODO: computeAccessibleName + expect(buttons[0]).to.have.accessibleName('Clear'); expect(buttons[0]).to.have.attribute('title', 'Clear'); - // TODO: computeAccessibleName + expect(buttons[1]).to.have.accessibleName('Close'); expect(buttons[1]).to.have.attribute('title', 'Close'); buttons.forEach(button => { expect(button, 'button is not in tab order').to.have.property('tabIndex', -1); diff --git a/packages/material-ui/src/Chip/Chip.test.js b/packages/material-ui/src/Chip/Chip.test.js index 98600b09691a23..669213487dba1e 100644 --- a/packages/material-ui/src/Chip/Chip.test.js +++ b/packages/material-ui/src/Chip/Chip.test.js @@ -75,8 +75,7 @@ describe('', () => { const button = getByRole('button'); expect(button).to.have.property('tabIndex', 0); - // TODO: accessible name computation - expect(button).to.have.text('My Chip'); + expect(button).to.have.accessibleName('My Chip'); }); it('should apply user value of tabIndex', () => { diff --git a/packages/material-ui/src/Select/Select.test.js b/packages/material-ui/src/Select/Select.test.js index a898521cb92a80..ad79a6137de0d5 100644 --- a/packages/material-ui/src/Select/Select.test.js +++ b/packages/material-ui/src/Select/Select.test.js @@ -406,6 +406,7 @@ describe('); + // TODO what is the accessible name actually? expect(getByRole('button')).to.have.attribute('aria-labelledby', ' '); }); diff --git a/packages/material-ui/src/TextField/TextField.test.js b/packages/material-ui/src/TextField/TextField.test.js index fa47f18bacf7da..ddb2ea49d90989 100644 --- a/packages/material-ui/src/TextField/TextField.test.js +++ b/packages/material-ui/src/TextField/TextField.test.js @@ -160,14 +160,7 @@ describe('', () => { , ); - const label = getByRole('button') - .getAttribute('aria-labelledby') - .split(' ') - .map(idref => document.getElementById(idref)) - .reduce((partial, element) => `${partial} ${element.textContent}`, ''); - // this whitespace is ok since actual AT will only use so called "flat strings" - // https://w3c.github.io/accname/#mapping_additional_nd_te - expect(label).to.equal(' Release: Stable'); + expect(getByRole('button')).to.have.accessibleName('Release: Stable'); }); it('creates an input[hidden] that has no accessible properties', () => { diff --git a/packages/material-ui/test/integration/Select.test.js b/packages/material-ui/test/integration/Select.test.js index c356ac6a3854a8..b8d4e52b8b5f3c 100644 --- a/packages/material-ui/test/integration/Select.test.js +++ b/packages/material-ui/test/integration/Select.test.js @@ -75,9 +75,7 @@ describe(' integration', () => { }); describe('with label', () => { + it('requires `id` and `labelId` for a proper accessible name', () => { + const { getByRole } = render( + + Age + + , + ); + + expect(getByRole('button')).to.have.accessibleName('Age Ten'); + }); + // we're somewhat abusing "focus" here. What we're actually interested in is // displaying it as "active". WAI-ARIA authoring practices do not consider the // the trigger part of the widget while a native + @@ -117,7 +129,7 @@ describe('