Skip to content

Commit

Permalink
fix: menu SSR (#319)
Browse files Browse the repository at this point in the history
- replace DOM-dependent `className` ternary with explicit param
  • Loading branch information
uipoet authored Apr 21, 2022
1 parent dff2245 commit 3e61a97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/menu/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function ButtonMenu({
refMenu,
style,
setExpanded,
} = useMenu<HTMLButtonElement>({ classNameOverride, id });
} = useMenu<HTMLButtonElement>({ classNameOverride, element: "Button", id });

return (
<fieldset className={className} ref={refFieldset}>
Expand Down
5 changes: 3 additions & 2 deletions src/lib/components/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ export type MenuOption =

export function useMenu<T>({
classNameOverride,
element,
flex,
id,
}: {
flex?: boolean;
id: string;
classNameOverride?: string;
element: "Button" | "Input";
}) {
const [expanded, setExpanded] = useState(false);
const refControl = useRef<T | null>(null);
Expand Down Expand Up @@ -98,8 +100,7 @@ export function useMenu<T>({
className: classNames({
[styles.fieldset]: true,
[styles.flex]: flex,
[refControl instanceof HTMLInputElement ? styles.input : styles.button]:
true,
[element === "Button" ? styles.button : styles.input]: true,
classNameOverride,
}),
expanded,
Expand Down
7 changes: 6 additions & 1 deletion src/lib/components/menu/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export const InputMenu = forwardRef<
refMenu,
setExpanded,
style,
} = useMenu<HTMLInputElement>({ classNameOverride, flex, id });
} = useMenu<HTMLInputElement>({
classNameOverride,
element: "Input",
flex,
id,
});

return (
<fieldset className={className} ref={refFieldset}>
Expand Down

0 comments on commit 3e61a97

Please sign in to comment.