Skip to content

Commit

Permalink
add dropdown primitive ctd
Browse files Browse the repository at this point in the history
  • Loading branch information
amk221 committed Dec 10, 2024
1 parent 996cb26 commit 3dba788
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 33 deletions.
6 changes: 1 addition & 5 deletions addon/components/select-box/index.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ export default class SelectBox extends Component {
}

get optionsTabIndex() {
return this.isListBox ? '0' : null;
}

get dropdownTabIndex() {
return this.dropdown ? '-1' : null;
return this.isListBox ? '0' : '-1';
}

get triggerTabIndex() {
Expand Down
5 changes: 0 additions & 5 deletions tests/dummy/app/components/custom-button.gjs

This file was deleted.

15 changes: 0 additions & 15 deletions tests/dummy/app/controllers/custom-trigger.js

This file was deleted.

4 changes: 2 additions & 2 deletions tests/dummy/app/templates/dropdown.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<div>
Non interactive element
</div>
<a href="#">
<LinkTo @route="dropdown">
Interactive element
</a>
</LinkTo>
</dd.Content>
{{/if}}
</Dropdown>
3 changes: 2 additions & 1 deletion tests/integration/components/select-box/index/api-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module('select-box (api)', function (hooks) {
setupRenderingTest(hooks);

test('api', async function (assert) {
assert.expect(16);
assert.expect(17);

let api;
let api2;
Expand Down Expand Up @@ -47,6 +47,7 @@ module('select-box (api)', function (hooks) {
assert.strictEqual(typeof api.Options, 'object');
assert.strictEqual(typeof api.Dropdown, 'object');
assert.strictEqual(typeof api.Trigger, 'object');
assert.strictEqual(typeof api.Content, 'object');

// Properties
assert.deepEqual(api.element, find('.select-box'));
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/components/select-box/index/focus-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ module('select-box (focus)', function (hooks) {
});

test('keyboard-focusable-scrollers fix', async function (assert) {
assert.expect(2);
assert.expect(3);

// we use tabindex="-1" on the dropdown content to prevent
// keyboard-focusable-scrollers from stealing focus, but
Expand All @@ -635,8 +635,9 @@ module('select-box (focus)', function (hooks) {
//
// here, when the primary interactive element is focused,
// and the user presses tab, we always want focus to move
// to the next interactive element. skipping the overflowing
// dropdown content.
// to the next interactive element. skipping the dropdown
// content (if it was overflowing), and also skipping over
// the listbox (if it was overflowing).

let event;

Expand All @@ -658,6 +659,7 @@ module('select-box (focus)', function (hooks) {
await click('.select-box__options');

assert.dom('.dropdown__content').hasAttribute('tabindex', '-1');
assert.dom('.select-box__options').hasAttribute('tabindex', '-1');
assert.true(event.defaultPrevented);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ module('select-box/options', function (hooks) {
</SelectBox>
</template>);

assert.dom('.select-box__options').doesNotHaveAttribute(
assert.dom('.select-box__options').hasAttribute(
'tabindex',
'-1',
`the main interactive element is the input (combobox)
focus should not move to the listbox, which is
aria controlled virtually by the input.`
Expand All @@ -92,8 +93,9 @@ module('select-box/options', function (hooks) {
</SelectBox>
</template>);

assert.dom('.select-box__options').doesNotHaveAttribute(
assert.dom('.select-box__options').hasAttribute(
'tabindex',
'-1',
`the main interactive element is the trigger (combobox)
focus should not move to the listbox (options element), which is
aria controlled virtually by the trigger`
Expand Down

0 comments on commit 3dba788

Please sign in to comment.