Skip to content

Commit

Permalink
fix: Playground example model selector working (shadcn-ui#4507)
Browse files Browse the repository at this point in the history
Issue: 
The ModelItem component's onPeek handler was sometimes logging incorrect data, causing the model selector to appear inconsistent.

Changes Made:
Verified that the aria-selected attribute is true before calling onPeek(model), ensuring the function is only called when the element is actually selected.

Fixed Model Selector Inconsistency in Playground Example

fixes shadcn-ui#4506
  • Loading branch information
sbsangu authored Aug 7, 2024
1 parent f2e3341 commit 9f156a1
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ function ModelItem({ model, isSelected, onSelect, onPeek }: ModelItemProps) {
const ref = React.useRef<HTMLDivElement>(null)

useMutationObserver(ref, (mutations) => {
for (const mutation of mutations) {
if (mutation.type === "attributes") {
if (mutation.attributeName === "aria-selected") {
onPeek(model)
}
mutations.forEach((mutation) => {
if (
mutation.type === "attributes" &&
mutation.attributeName === "aria-selected" &&
ref.current?.getAttribute("aria-selected") === "true"
) {
onPeek(model);
}
}
})
});
});


return (
<CommandItem
Expand Down

0 comments on commit 9f156a1

Please sign in to comment.