Skip to content

Commit

Permalink
fix(keybinds): last fn respects disabled items (#47)
Browse files Browse the repository at this point in the history
* fix(keybinding): Meta+ArrowDown respects disabled items

* chore(keybinds): update test

* revert id change

* chore: update test

* remove .only

Co-authored-by: Paco <[email protected]>
  • Loading branch information
thiskevinwang and pacocoursey authored Sep 5, 2022
1 parent 9fae175 commit eb0947f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
}
}

const last = () => updateSelectedToIndex(state.current.filtered.count - 1)
const last = () => updateSelectedToIndex(getValidItems().length - 1)

const next = (e: React.KeyboardEvent) => {
e.preventDefault()
Expand Down
9 changes: 9 additions & 0 deletions test/pages/keybinds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const Page = () => {
<Command.List>
<Command.Empty>No results.</Command.Empty>

<Command.Item value="disabled" disabled>
Disabled
</Command.Item>

<Command.Item value="first">First</Command.Item>

<Command.Group heading="Letters">
Expand All @@ -21,10 +25,15 @@ const Page = () => {
<Command.Item>Apple</Command.Item>
<Command.Item>Banana</Command.Item>
<Command.Item>Orange</Command.Item>
<Command.Item disabled>Dragon Fruit</Command.Item>
<Command.Item>Pear</Command.Item>
</Command.Group>

<Command.Item value="last">Last</Command.Item>

<Command.Item value="disabled-3" disabled>
Disabled 3
</Command.Item>
</Command.List>
</Command>
</div>
Expand Down

1 comment on commit eb0947f

@vercel
Copy link

@vercel vercel bot commented on eb0947f Sep 5, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

cmdk-website – ./

cmdk-website-git-main-paco.vercel.app
cmdk.vercel.app
cmdk-website-paco.vercel.app
cmdk.paco.me

Please sign in to comment.