Skip to content

Commit

Permalink
fix: Now forwards ref from SelectableFab allowing Tooltip usage
Browse files Browse the repository at this point in the history
  • Loading branch information
evrys committed Sep 30, 2024
1 parent 825fc8a commit 3d67faf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
24 changes: 14 additions & 10 deletions src/components/SelectableFab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Fab, styled, type FabProps } from "@mui/material"
import { forwardRef, type Ref } from "react"

const StyledSelectableFab = styled(Fab, {
shouldForwardProp: (prop) => prop !== "selected",
Expand Down Expand Up @@ -35,13 +36,16 @@ type CodeFabProps = {
selected?: boolean
} & Omit<FabProps, "variant" | "color">

export function SelectableFab({ selected, ...props }: CodeFabProps) {
return (
<StyledSelectableFab
selected={selected}
{...props}
color={"secondary"}
variant="circular"
/>
)
}
export const SelectableFab = forwardRef(
(props: CodeFabProps, ref: Ref<HTMLButtonElement>) => {
return (
<StyledSelectableFab
ref={ref}
selected={props.selected}
{...props}
color={"secondary"}
variant="circular"
/>
)
},
)
13 changes: 6 additions & 7 deletions stories/MuiSamples/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import AddIcon from "@mui/icons-material/Add";
import DeleteIcon from "@mui/icons-material/Delete";
import Fab from "@mui/material/Fab";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import React from "react";
import AddIcon from "@mui/icons-material/Add"
import DeleteIcon from "@mui/icons-material/Delete"
import Fab from "@mui/material/Fab"
import IconButton from "@mui/material/IconButton"
import Tooltip from "@mui/material/Tooltip"

export default function TooltipExample() {
return (
Expand All @@ -24,5 +23,5 @@ export default function TooltipExample() {
</Fab>
</Tooltip>
</div>
);
)
}

0 comments on commit 3d67faf

Please sign in to comment.