pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.42k stars 265 forks source link

How to make SubItem render other items #66

Closed Mbensler closed 1 year ago

Mbensler commented 1 year ago

I am trying to make my SubItem render something like this:

{searchItems.map(({ icon, label }) => {
    return (
        <SubItem key={label}>
            <div>
                <img src={icon} />
                <p>{label}</p>
            </div>
        </SubItem>;
    )
})}

But it won´t work like this.

It will only work when it looks like this:

{searchItems.map(({ icon, label }) => {
    return 
        <SubItem key={label}>
            {label}
        </SubItem>;
})}

Then it shows up correctly. If I were to do {icon} {label} it doesn't work either.

It seems like it only accepts one thing, and I am trying to get it to look like a normal Command.Item with an icon on the left and text next to it without a shortcut.

pacocoursey commented 1 year ago

I don't fully understand your question without a minimal reproduction, but please try passing a unique value prop to each Command.Item to ensure everything works as expected. Then report back :)

Mbensler commented 1 year ago

I was missing the value prop. It works now. Thank you very much.