Skip to content

Commit

Permalink
fix(material): untrack focus call
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Nov 22, 2022
1 parent 64eae19 commit c4a5197
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-dolls-compare.md
@@ -0,0 +1,5 @@
---
"@suid/material": patch
---

Fix `autoFocus` property in `MenuItem` component
9 changes: 5 additions & 4 deletions packages/material/src/MenuItem/MenuItem.tsx
Expand Up @@ -16,7 +16,8 @@ import {
useContext,
splitProps,
mergeProps,
createRenderEffect,
createEffect,
untrack,
} from "solid-js";

const $ = createComponentFactory<MenuItemTypeMap>()({
Expand Down Expand Up @@ -202,17 +203,17 @@ const MenuItem = $.defineComponent(function MenuItem(inProps) {
},
};

createRenderEffect(() => {
createEffect(() => {
if (baseProps.autoFocus) {
if (menuItemRef.current) {
menuItemRef.current.focus();
untrack(() => menuItemRef.current.focus());
} else if (process.env.NODE_ENV !== "production") {
console.error(
"MUI: Unable to set focus to a MenuItem whose component has not been rendered."
);
}
}
}, [baseProps.autoFocus]);
});

const ownerState = mergeProps(props, {
get dense() {
Expand Down

0 comments on commit c4a5197

Please sign in to comment.