mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-10 00:27:41 +08:00
fix(alert): stop Enter keypress for checkboxes (#28279)
This commit is contained in:
@ -228,6 +228,15 @@ export class Alert implements ComponentInterface, OverlayInterface {
|
|||||||
onKeydown(ev: any) {
|
onKeydown(ev: any) {
|
||||||
const inputTypes = new Set(this.processedInputs.map((i) => i.type));
|
const inputTypes = new Set(this.processedInputs.map((i) => i.type));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on keyboard navigation requirements, the
|
||||||
|
* checkbox should not respond to the enter keydown event.
|
||||||
|
*/
|
||||||
|
if (inputTypes.has('checkbox') && ev.key === 'Enter') {
|
||||||
|
ev.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// The only inputs we want to navigate between using arrow keys are the radios
|
// The only inputs we want to navigate between using arrow keys are the radios
|
||||||
// ignore the keydown event if it is not on a radio button
|
// ignore the keydown event if it is not on a radio button
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -76,5 +76,22 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
|
|||||||
await expect(alertButton).toHaveAttribute('aria-labelledby', 'close-label');
|
await expect(alertButton).toHaveAttribute('aria-labelledby', 'close-label');
|
||||||
await expect(alertButton).toHaveAttribute('aria-label', 'close button');
|
await expect(alertButton).toHaveAttribute('aria-label', 'close button');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should not toggle the checkbox when pressing the Enter key', async ({ page }) => {
|
||||||
|
const didPresent = await page.spyOnEvent('ionAlertDidPresent');
|
||||||
|
|
||||||
|
const button = page.locator('#checkbox');
|
||||||
|
await button.click();
|
||||||
|
|
||||||
|
await didPresent.next();
|
||||||
|
|
||||||
|
const alertCheckbox = page.locator('ion-alert .alert-checkbox');
|
||||||
|
const ariaChecked = await alertCheckbox.getAttribute('aria-checked');
|
||||||
|
|
||||||
|
await expect(alertCheckbox).toHaveAttribute('aria-checked', ariaChecked!);
|
||||||
|
|
||||||
|
await alertCheckbox.press('Enter');
|
||||||
|
await expect(alertCheckbox).toHaveAttribute('aria-checked', ariaChecked!);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -25,6 +25,7 @@
|
|||||||
<ion-button id="noMessage" expand="block" onclick="presentNoMessage()">No Message</ion-button>
|
<ion-button id="noMessage" expand="block" onclick="presentNoMessage()">No Message</ion-button>
|
||||||
<ion-button id="customAria" expand="block" onclick="presentCustomAria()">Custom Aria</ion-button>
|
<ion-button id="customAria" expand="block" onclick="presentCustomAria()">Custom Aria</ion-button>
|
||||||
<ion-button id="ariaLabelButton" expand="block" onclick="presentAriaLabelButton()">Aria Label Button</ion-button>
|
<ion-button id="ariaLabelButton" expand="block" onclick="presentAriaLabelButton()">Aria Label Button</ion-button>
|
||||||
|
<ion-button id="checkbox" expand="block" onclick="presentAlertCheckbox()">Checkbox</ion-button>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -94,6 +95,21 @@
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function presentAlertCheckbox() {
|
||||||
|
openAlert({
|
||||||
|
header: 'Checkbox',
|
||||||
|
inputs: [
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
label: 'Checkbox 1',
|
||||||
|
value: 'value1',
|
||||||
|
checked: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
buttons: ['OK'],
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user