Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://open-ui.org/components/combobox.explainer">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<input list=datalist>
<datalist id=datalist>
<option class=one>one</option>
<option class=two>two</option>
<option class=three>three</option>
</datalist>

<style>
input, datalist {
appearance: base;
}
</style>

<script>
function visibleOptions() {
return Array.from(document.querySelectorAll('option:not(:filtered)'));
}

promise_test(async () => {
const input = document.querySelector('input');
const datalist = document.querySelector('datalist');
const optionOne = document.querySelector('.one');
const optionTwo = document.querySelector('.two');
const optionThree = document.querySelector('.three');

input.focus();
assert_true(datalist.matches(':popover-open'),
'Datalist should open after focusing the input.');
assert_array_equals(visibleOptions(), [optionOne, optionTwo, optionThree],
'No options should be filtered out at the start of the test.');

input.value = 'z';
assert_array_equals(visibleOptions(), [],
'All options should be filtered out after setting value to z.');

input.value = 't';
assert_array_equals(visibleOptions(), [optionTwo, optionThree],
'Options two and three should be visible after setting value to t.');

let beforefilters = 0;
input.onbeforefilter = event => {
beforefilters++;
event.preventDefault();
};
input.value = 'z';
assert_equals(beforefilters, 1,
'The beforefilter event should fire when assigning to input.value.');
assert_array_equals(visibleOptions(), [optionTwo, optionThree],
'Filtering should not change after preventing beforefilter event.');
}, 'beforefilter event for customizable combobox.');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://open-ui.org/components/combobox.explainer">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<input filter=select>
<select id=select size=4>
<option class=one>one</option>
<option class=two>two</option>
<option class=three>three</option>
</select>

<style>
input, select {
appearance: base;
}
</style>

<script>
function visibleOptions() {
return Array.from(document.querySelectorAll('option:not(:filtered)'));
}

promise_test(async () => {
const input = document.querySelector('input');
const select = document.querySelector('select');
const optionOne = document.querySelector('.one');
const optionTwo = document.querySelector('.two');
const optionThree = document.querySelector('.three');

assert_array_equals(visibleOptions(), [optionOne, optionTwo, optionThree],
'No options should be filtered out at the start of the test.');

input.value = 'z';
assert_array_equals(visibleOptions(), [],
'All options should be filtered out after setting value to z.');

input.value = 't';
assert_array_equals(visibleOptions(), [optionTwo, optionThree],
'Options two and three should be visible after setting value to t.');

let beforefilters = 0;
input.onbeforefilter = event => {
beforefilters++;
event.preventDefault();
};
input.value = 'z';
assert_equals(beforefilters, 1,
'The beforefilter event should fire when assigning to input.value.');
assert_array_equals(visibleOptions(), [optionTwo, optionThree],
'Filtering should not change after preventing beforefilter event.');
}, 'beforefilter event for customizable combobox.');
</script>
Loading