mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-27 05:46:28 +03:00
fix(check): allow checking/unchecking role=radio elements (#8821)
We already do this for `role=checkbox` but not for radio.
This commit is contained in:
parent
7bbb63d143
commit
e85fba1c7d
@ -474,7 +474,7 @@ export class InjectedScript {
|
|||||||
return !disabled && editable;
|
return !disabled && editable;
|
||||||
|
|
||||||
if (state === 'checked') {
|
if (state === 'checked') {
|
||||||
if (element.getAttribute('role') === 'checkbox')
|
if (['checkbox', 'radio'].includes(element.getAttribute('role') || ''))
|
||||||
return element.getAttribute('aria-checked') === 'true';
|
return element.getAttribute('aria-checked') === 'true';
|
||||||
if (element.nodeName !== 'INPUT')
|
if (element.nodeName !== 'INPUT')
|
||||||
return 'error:notcheckbox';
|
return 'error:notcheckbox';
|
||||||
|
@ -85,6 +85,24 @@ it('should check radio', async ({page}) => {
|
|||||||
expect(await page.evaluate(() => window['two'].checked)).toBe(true);
|
expect(await page.evaluate(() => window['two'].checked)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should check radio by aria role', async ({page}) => {
|
||||||
|
await page.setContent(`<div role='radio' id='checkbox'>CHECKBOX</div>
|
||||||
|
<script>
|
||||||
|
checkbox.addEventListener('click', () => checkbox.setAttribute('aria-checked', 'true'));
|
||||||
|
</script>`);
|
||||||
|
await page.check('div');
|
||||||
|
expect(await page.evaluate(() => window['checkbox'].getAttribute('aria-checked'))).toBe('true');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should uncheck radio by aria role', async ({page}) => {
|
||||||
|
await page.setContent(`<div role='radio' id='checkbox' aria-checked="true">CHECKBOX</div>
|
||||||
|
<script>
|
||||||
|
checkbox.addEventListener('click', () => checkbox.setAttribute('aria-checked', 'false'));
|
||||||
|
</script>`);
|
||||||
|
await page.uncheck('div');
|
||||||
|
expect(await page.evaluate(() => window['checkbox'].getAttribute('aria-checked'))).toBe('false');
|
||||||
|
});
|
||||||
|
|
||||||
it('should check the box by aria role', async ({page}) => {
|
it('should check the box by aria role', async ({page}) => {
|
||||||
await page.setContent(`<div role='checkbox' id='checkbox'>CHECKBOX</div>
|
await page.setContent(`<div role='checkbox' id='checkbox'>CHECKBOX</div>
|
||||||
<script>
|
<script>
|
||||||
@ -94,6 +112,15 @@ it('should check the box by aria role', async ({page}) => {
|
|||||||
expect(await page.evaluate(() => window['checkbox'].getAttribute('aria-checked'))).toBe('true');
|
expect(await page.evaluate(() => window['checkbox'].getAttribute('aria-checked'))).toBe('true');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should uncheck the box by aria role', async ({page}) => {
|
||||||
|
await page.setContent(`<div role='checkbox' id='checkbox' aria-checked="true">CHECKBOX</div>
|
||||||
|
<script>
|
||||||
|
checkbox.addEventListener('click', () => checkbox.setAttribute('aria-checked', 'false'));
|
||||||
|
</script>`);
|
||||||
|
await page.uncheck('div');
|
||||||
|
expect(await page.evaluate(() => window['checkbox'].getAttribute('aria-checked'))).toBe('false');
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw when not a checkbox', async ({page}) => {
|
it('should throw when not a checkbox', async ({page}) => {
|
||||||
await page.setContent(`<div>Check me</div>`);
|
await page.setContent(`<div>Check me</div>`);
|
||||||
const error = await page.check('div').catch(e => e);
|
const error = await page.check('div').catch(e => e);
|
||||||
|
Loading…
Reference in New Issue
Block a user