Skip to content

Commit

Permalink
Fix dropdown combobox focus (#447)
Browse files Browse the repository at this point in the history
* fix(combo-box): selecting a different combobox should focus the input

* fix(dropdown): selecting a different dropdown should focus the button

* fix(combo-box): focus input if related target attribute is not "searchbox"
  • Loading branch information
metonym authored Dec 5, 2020
1 parent 222c7f2 commit f6877f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/ComboBox/ComboBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
*/
export let listRef = null;
import { createEventDispatcher, afterUpdate } from "svelte";
import { createEventDispatcher, afterUpdate, tick } from "svelte";
import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16";
import {
ListBox,
Expand Down Expand Up @@ -173,9 +173,11 @@
<ListBoxField
role="button"
aria-expanded="{open}"
on:click="{() => {
on:click="{async () => {
if (disabled) return;
open = true;
await tick();
ref.focus();
}}"
id="{id}"
name="{name}"
Expand Down Expand Up @@ -220,7 +222,8 @@
on:focus
on:blur
on:blur="{({ relatedTarget }) => {
if (relatedTarget && relatedTarget.getAttribute('role') !== 'button') {
if (!open || !relatedTarget) return;
if (relatedTarget.getAttribute('role') !== 'button' && relatedTarget.getAttribute('role') !== 'searchbox') {
ref.focus();
}
}}"
Expand Down
6 changes: 1 addition & 5 deletions src/Dropdown/Dropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@
change(-1);
}
}}"
on:blur="{({ relatedTarget }) => {
if (relatedTarget) {
ref.focus();
}
}}"
disabled="{disabled}"
translateWithId="{translateWithId}"
id="{id}"
Expand All @@ -213,6 +208,7 @@
on:click="{() => {
selectedId = item.id;
selectedIndex = i;
ref.focus();
}}"
on:mouseenter="{() => {
highlightedIndex = i;
Expand Down

1 comment on commit f6877f3

@vercel
Copy link

@vercel vercel bot commented on f6877f3 Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.