Skip to content

Commit

Permalink
fix(IconButton): infer addtional props from as prop (#2343)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Feb 10, 2022
1 parent fd0907e commit 3b6c25c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/components/LanguageButton/LanguageButton.tsx
Expand Up @@ -12,7 +12,7 @@ interface ButtonProps {
[key: string]: any;
}

const LanguageButton = React.forwardRef((props: ButtonProps, ref) => {
const LanguageButton = React.forwardRef((props: ButtonProps, ref: React.Ref<HTMLElement>) => {
const router = useRouter();
const { language, onChangeLanguage } = React.useContext(AppContext);
const { className, ...rest } = props;
Expand Down
12 changes: 9 additions & 3 deletions src/IconButton/IconButton.tsx
@@ -1,8 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import Button, { ButtonProps } from '../Button';
import { useClassNames } from '../utils';
import { IconProps } from '@rsuite/icons/lib/Icon';
import { RsRefForwardingComponent } from '../@types/common';
import { useClassNames } from '../utils';
import Button, { ButtonProps } from '../Button';

export interface IconButtonProps extends ButtonProps {
/** Set the icon */
Expand All @@ -15,7 +16,12 @@ export interface IconButtonProps extends ButtonProps {
placement?: 'left' | 'right';
}

const IconButton = React.forwardRef((props: IconButtonProps, ref) => {
const IconButton: RsRefForwardingComponent<
typeof Button,
IconButtonProps & {
ref?: React.Ref<HTMLElement>;
}
> = React.forwardRef((props: IconButtonProps, ref) => {
const {
icon,
placement = 'left',
Expand Down
9 changes: 9 additions & 0 deletions src/IconButton/test/IconButton.test.tsx
@@ -0,0 +1,9 @@
import React from 'react';
import IconButton from '../IconButton';

const Link = ({ to }: { to: string }) => <a href={to} />;

const ref = React.createRef<HTMLButtonElement>();

// Infer `as` component props
<IconButton ref={ref} as={Link} to="/home" />;

1 comment on commit 3b6c25c

@vercel
Copy link

@vercel vercel bot commented on 3b6c25c Feb 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.