Commit 9145974e authored by Daniel Libby's avatar Daniel Libby Committed by Commit Bot

Ensure `input` and `change` events fire when selecting an <option>

When a native click accessibility operation is performed on an option
element that is part of a select popup, we mark the option as selected,
then do a native click on the parent select to dismiss it. This
sequence of operations ends up not firing `input` and `change` events,
which normally happens as part of the popup being dismissed by the
click in the normal case.

However, the AccessKeyAction for option takes care of this, so we
perform that operation instead of directly setting the option as
selected.


Bug: 1143990
Change-Id: Ied6023b4b2aee759575eebf75a32b7f2720f3068
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508884Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarVictor Fei <vicfei@microsoft.com>
Commit-Queue: Daniel Libby <dlibby@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#823312}
parent 279e732a
...@@ -130,14 +130,16 @@ bool AXMenuListOption::OnNativeClickAction() { ...@@ -130,14 +130,16 @@ bool AXMenuListOption::OnNativeClickAction() {
if (!element_) if (!element_)
return false; return false;
// Clicking on an option within a menu list should first select that item, if (IsA<AXMenuListPopup>(ParentObject())) {
// then toggle whether the menu list is showing. // Clicking on an option within a menu list should first select that item
element_->SetSelected(true); // (which should include firing `input` and `change` events), then toggle
// whether the menu list is showing.
// Calling OnNativeClickAction on the parent select element will toggle static_cast<HTMLElement*>(element_)->AccessKeyAction(true);
// it open or closed.
if (IsA<AXMenuListPopup>(ParentObject())) // Calling OnNativeClickAction on the parent select element will toggle
// it open or closed.
return ParentObject()->OnNativeClickAction(); return ParentObject()->OnNativeClickAction();
}
return AXNodeObject::OnNativeClickAction(); return AXNodeObject::OnNativeClickAction();
} }
......
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<select id="select">
<option id="option1">1</option>
<option id="option2">2</option>
<option id="option3">2</option>
</select>
<script>
function axElementById(id) {
return accessibilityController.accessibleElementById(id);
}
async_test(t => {
let select = document.querySelector('select');
select.addEventListener("change", t.step_func(e => {
assert_equals(e.target.value, "2", "`change` event must fire for '2' on the select element");
t.done();
}));
// Press on the select to show the popup.
let axSelect = axElementById('select');
select.focus();
axSelect.press();
requestAnimationFrame(t.step_func(() => {
// Once the popup is shown, click on another option, which must fire the event
let axOption2 = axElementById('option2');
axOption2.press();
t.step_timeout(t.unreached_func("`change` event never fired"), 100);
}));
}, 'When performing a click through a11y on an option in a select popup, the change event must fire');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment