Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-Jayden committed Nov 19, 2023
1 parent af6c612 commit 3353cff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ You can make the arrow keys wrap around the list (when you reach the end, it goe
<Command.Root loop />
```

This component also exposes two additional slot props for `state` (the current reactive value of the command state) and `stateStore` (the underlying writable state store). These can be used to implement more advanced use cases, such as debouncing the search updates with the `stateStore.updateState` method:

```svelte
<Command.Root {state} let:stateStore>
{@const handleUpdateState = debounce(stateStore.updateState, 200)}
<CustomCommandInput {handleUpdateState} />
</Command.Root>
```

### Dialog `[cmdk-dialog]` `[cmdk-overlay]`

Props are forwarded to [Command](#command-cmdk-root). Composes Bits UI's Dialog component. The overlay is always rendered. See the [Bits Documentation](https://bits-ui.com/docs/) for more information. Can be controlled by binding to the `open` prop.
Expand Down
11 changes: 9 additions & 2 deletions src/lib/cmdk/components/Command.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,23 @@
action: rootAction,
attrs: rootAttrs
};
$: slotProps = {
root,
label: { attrs: labelAttrs },
stateStore,
state: $stateStore
};
</script>

{#if asChild}
<slot {root} state={stateStore} label={{ attrs: labelAttrs }} />
<slot {...slotProps} />
{:else}
<div use:rootAction {...rootAttrs} {...$$restProps}>
<!-- svelte-ignore a11y-label-has-associated-control applied in attrs -->
<label {...labelAttrs}>
{label ?? ''}
</label>
<slot {root} state={stateStore} label={{ attrs: labelAttrs }} />
<slot {...slotProps} />
</div>
{/if}

0 comments on commit 3353cff

Please sign in to comment.