Skip to content

Commit

Permalink
remove lowercasing of value and keyword, fixes #150
Browse files Browse the repository at this point in the history
  • Loading branch information
pacocoursey committed Jan 30, 2024
1 parent 8aecf2d commit 3dae25d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Render this to show the command menu inline, or use [Dialog](#dialog-cmdk-dialog

> **Note**
>
> Values are always converted to lowercase and trimmed. Use `apple`, not `Apple`.
> Values are always trimmed. Use `apple`, not `Apple`.
```tsx
const [value, setValue] = React.useState('apple')
Expand All @@ -107,7 +107,7 @@ return (
)
```

You can provide a custom `filter` function that is called to rank each item. Both strings are normalized as lowercase and trimmed.
You can provide a custom `filter` function that is called to rank each item. Both strings are trimmed.

```tsx
<Command
Expand All @@ -118,7 +118,7 @@ You can provide a custom `filter` function that is called to rank each item. Bot
/>
```

A third argument, `keywords`, can also be provided to the filter function. Keywords act as aliases for the item value, and can also affect the rank of the item. Keywords are normalized as lowercase and trimmed.
A third argument, `keywords`, can also be provided to the filter function. Keywords act as aliases for the item value, and can also affect the rank of the item. Keywords are trimmed.

```tsx
<Command
Expand Down Expand Up @@ -224,7 +224,7 @@ Item that becomes active on pointer enter. You should provide a unique `value` f
</Command.Item>
```

You can also provide a `keywords` prop to help with filtering. Keywords are normalized as lowercase and trimmed.
You can also provide a `keywords` prop to help with filtering. Keywords are trimmed.

```tsx
<Command.Item keywords={['fruit', 'apple']}>Apple</Command.Item>
Expand Down
10 changes: 5 additions & 5 deletions cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
/** Value of the search query. */
search: '',
/** Currently selected item value. */
value: props.value ?? props.defaultValue?.toLowerCase() ?? '',
value: props.value ?? props.defaultValue ?? '',
filtered: {
/** The count of all visible items. */
count: 0,
Expand Down Expand Up @@ -206,7 +206,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
/** Controlled mode `value` handling. */
useLayoutEffect(() => {
if (value !== undefined) {
const v = value.trim().toLowerCase()
const v = value.trim()
state.current.value = v
store.emit()
}
Expand Down Expand Up @@ -1016,19 +1016,19 @@ function useValue(
const value = (() => {
for (const part of deps) {
if (typeof part === 'string') {
return part.trim().toLowerCase()
return part.trim()
}

if (typeof part === 'object' && 'current' in part) {
if (part.current) {
return part.current.textContent?.trim().toLowerCase()
return part.current.textContent?.trim()
}
return valueRef.current
}
}
})()

const keywords = (() => aliases.map((alias) => alias.trim().toLowerCase()))()
const keywords = aliases.map((alias) => alias.trim())

context.value(id, value, keywords)
ref.current?.setAttribute(VALUE_ATTR, value)
Expand Down

0 comments on commit 3dae25d

Please sign in to comment.