Improve AccessibleButton & related types (#12075)

* Fix wrong type enum usage

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Use improved type definition for forwardRef which enables Generic props

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Improve AccessibleButton & related Props types

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Remove useless comment

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2023-12-20 14:42:31 +00:00 committed by GitHub
parent e26d3e9b68
commit af31965866
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 109 additions and 79 deletions

View file

@ -25,7 +25,7 @@ import Tooltip, { Alignment } from "./Tooltip";
*
* Extends that of {@link AccessibleButton}.
*/
interface Props extends React.ComponentProps<typeof AccessibleButton> {
type Props<T extends keyof JSX.IntrinsicElements> = React.ComponentProps<typeof AccessibleButton<T>> & {
/**
* Title to show in the tooltip and use as aria-label
*/
@ -58,9 +58,9 @@ interface Props extends React.ComponentProps<typeof AccessibleButton> {
* Function to call when the tooltip goes from shown to hidden.
*/
onHideTooltip?(ev: SyntheticEvent): void;
}
};
function AccessibleTooltipButton({
function AccessibleTooltipButton<T extends keyof JSX.IntrinsicElements>({
title,
tooltip,
children,
@ -69,7 +69,7 @@ function AccessibleTooltipButton({
onHideTooltip,
tooltipClassName,
...props
}: Props): JSX.Element {
}: Props<T>): JSX.Element {
const [hover, setHover] = useState(false);
useEffect(() => {