Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
arihanv authored Jun 30, 2024
2 parents 5c20f33 + 541fad2 commit 95861a9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: pacocoursey
5 changes: 4 additions & 1 deletion cmdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-id": "^1.0.1",
"@radix-ui/react-primitive": "1.0.3"
},
"devDependencies": {
Expand All @@ -35,13 +36,15 @@
"sideEffects": false,
"repository": {
"type": "git",
"url": "git+https://github.com/pacocoursey/cmdk.git"
"url": "git+https://github.com/pacocoursey/cmdk.git",
"directory": "cmdk"
},
"bugs": {
"url": "https://github.com/pacocoursey/cmdk/issues"
},
"homepage": "https://github.com/pacocoursey/cmdk#readme",
"author": {
"name": "Paco",
"url": "https://github.com/pacocoursey"
}
}
25 changes: 18 additions & 7 deletions cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as RadixDialog from '@radix-ui/react-dialog'
import * as React from 'react'
import { commandScore } from './command-score'
import { Primitive } from '@radix-ui/react-primitive'
import { useId } from '@radix-ui/react-id'

type Children = { children?: React.ReactNode }
type DivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>
Expand Down Expand Up @@ -166,6 +167,16 @@ const useStore = () => React.useContext(StoreContext)
// @ts-ignore
const GroupContext = React.createContext<Group>(undefined)

const getId = (() => {
let i = 0
return () => `${i++}`
})()
const useIdCompatibility = () => {
React.useState(getId)
const [id] = React.useState(getId)
return 'cmdk' + id
}

const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwardedRef) => {
const state = useLazyRef<State>(() => ({
/** Value of the search query. */
Expand Down Expand Up @@ -200,9 +211,9 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
...etc
} = props

const listId = React.useId()
const labelId = React.useId()
const inputId = React.useId()
const listId = useId()
const labelId = useId()
const inputId = useId()

const listInnerRef = React.useRef<HTMLDivElement>(null)

Expand Down Expand Up @@ -403,7 +414,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
groups
.sort((a, b) => b[1] - a[1])
.forEach((group) => {
const element = listInnerRef.current.querySelector(
const element = listInnerRef.current?.querySelector(
`${GROUP_SELECTOR}[${VALUE_ATTR}="${encodeURIComponent(group[0])}"]`,
)
element?.parentElement.appendChild(element)
Expand Down Expand Up @@ -647,7 +658,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
* the rendered item's `textContent`.
*/
const Item = React.forwardRef<HTMLDivElement, ItemProps>((props, forwardedRef) => {
const id = React.useId()
const id = useId()
const ref = React.useRef<HTMLDivElement>(null)
const groupContext = React.useContext(GroupContext)
const context = useCommand()
Expand Down Expand Up @@ -713,10 +724,10 @@ const Item = React.forwardRef<HTMLDivElement, ItemProps>((props, forwardedRef) =
*/
const Group = React.forwardRef<HTMLDivElement, GroupProps>((props, forwardedRef) => {
const { heading, children, forceMount, ...etc } = props
const id = React.useId()
const id = useId()
const ref = React.useRef<HTMLDivElement>(null)
const headingRef = React.useRef<HTMLDivElement>(null)
const headingId = React.useId()
const headingId = useId()
const context = useCommand()
const render = useCmdk((state) =>
forceMount ? true : context.filter() === false ? true : !state.search ? true : state.filtered.groups.has(id),
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 95861a9

Please sign in to comment.