mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
fix(list-box-menu-item): scroll item into view when using keyboard navigation (#1471)
Fixes #1470
This commit is contained in:
parent
740c8e1596
commit
7030300186
2 changed files with 6 additions and 2 deletions
|
@ -261,7 +261,7 @@
|
||||||
<ListBoxMenuItem
|
<ListBoxMenuItem
|
||||||
id="{item.id}"
|
id="{item.id}"
|
||||||
active="{selectedId === item.id}"
|
active="{selectedId === item.id}"
|
||||||
highlighted="{highlightedIndex === i || selectedId === item.id}"
|
highlighted="{highlightedIndex === i}"
|
||||||
disabled="{item.disabled}"
|
disabled="{item.disabled}"
|
||||||
on:click="{(e) => {
|
on:click="{(e) => {
|
||||||
if (item.disabled) {
|
if (item.disabled) {
|
||||||
|
|
|
@ -12,13 +12,17 @@
|
||||||
|
|
||||||
$: isTruncated = ref?.offsetWidth < ref?.scrollWidth;
|
$: isTruncated = ref?.offsetWidth < ref?.scrollWidth;
|
||||||
$: title = isTruncated ? ref?.innerText : undefined;
|
$: title = isTruncated ? ref?.innerText : undefined;
|
||||||
|
$: if (highlighted && !ref?.matches(":hover")) {
|
||||||
|
// Scroll highlighted item into view if using keyboard navigation
|
||||||
|
ref.scrollIntoView({ block: "end" });
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
role="option"
|
role="option"
|
||||||
class:bx--list-box__menu-item="{true}"
|
class:bx--list-box__menu-item="{true}"
|
||||||
class:bx--list-box__menu-item--active="{active}"
|
class:bx--list-box__menu-item--active="{active}"
|
||||||
class:bx--list-box__menu-item--highlighted="{highlighted}"
|
class:bx--list-box__menu-item--highlighted="{highlighted || active}"
|
||||||
aria-selected="{active}"
|
aria-selected="{active}"
|
||||||
disabled="{disabled ? true : undefined}"
|
disabled="{disabled ? true : undefined}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue