Skip to content

Commit 5d2972e

Browse files
committed
fix(group): fix group sort error
Fix the issue with group sorting not working. The root cause of the error is using the group ID to match the data-value. Signed-off-by: 刘圳 <liu.zhen@xsky.com>
1 parent 541fad2 commit 5d2972e

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

cmdk/src/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,7 @@ const Command = React.forwardRef<HTMLDivElement, CommandProps>((props, forwarded
410410
groups
411411
.sort((a, b) => b[1] - a[1])
412412
.forEach((group) => {
413-
const element = listInnerRef.current?.querySelector(
414-
`${GROUP_SELECTOR}[${VALUE_ATTR}="${encodeURIComponent(group[0])}"]`,
415-
)
413+
const element = listInnerRef.current?.querySelector(`#${group[0].replace(/:/g, '\\:')}`)
416414
element?.parentElement.appendChild(element)
417415
})
418416
}
@@ -742,6 +740,7 @@ const Group = React.forwardRef<HTMLDivElement, GroupProps>((props, forwardedRef)
742740
cmdk-group=""
743741
role="presentation"
744742
hidden={render ? undefined : true}
743+
id={id}
745744
>
746745
{heading && (
747746
<div ref={headingRef} cmdk-group-heading="" aria-hidden id={headingId}>

0 commit comments

Comments
 (0)