Skip to content

Commit

Permalink
[@mantine/spotlight] Fix DOM error thrown after HMR and several other…
Browse files Browse the repository at this point in the history
… cases (#4992)
  • Loading branch information
DenisBessa authored Oct 12, 2023
1 parent 3ea73f8 commit b326812
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/mantine-spotlight/src/spotlight.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export function setListId(id: string, store: SpotlightStore) {

export function selectAction(index: number, store: SpotlightStore): number {
const state = store.getState();
const actionsList = document.getElementById(state.listId)!;
const selected = actionsList.querySelector<HTMLButtonElement>('[data-selected]');
const actions = actionsList.querySelectorAll<HTMLButtonElement>('[data-action]');
const actionsList = document.getElementById(state.listId);
const selected = actionsList?.querySelector<HTMLButtonElement>('[data-selected]');
const actions = actionsList?.querySelectorAll<HTMLButtonElement>('[data-action]') ?? [];
const nextIndex = index === -1 ? actions.length - 1 : index === actions.length ? 0 : index;

const selectedIndex = clamp(nextIndex, 0, actions.length - 1);
Expand Down

0 comments on commit b326812

Please sign in to comment.