Skip to content

Commit 8d5e8e6

Browse files
committed
[QF-3593] refactor button component for ref
1 parent 418282d commit 8d5e8e6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/components/dls/Button/Button.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ export enum ButtonVariant {
4242
Accent = 'accent',
4343
}
4444

45+
/**
46+
* Props for the Button component.
47+
*
48+
* **Important**: When `href` is provided, the component renders a `<Link>` with a `<div>` inside instead of a `<button>`.
49+
* In this case, the `ref` parameter will not be forwarded and will be `null` when accessed by consumers.
50+
* If you need to access the underlying element via ref, avoid using the `href` prop.
51+
*/
4552
export type ButtonProps = {
4653
size?: ButtonSize;
4754
shape?: ButtonShape;
@@ -68,6 +75,14 @@ export type ButtonProps = {
6875
id?: string;
6976
};
7077

78+
/**
79+
* Button component that can render as either a button or a link.
80+
*
81+
* @param ref - Forwarded ref to the underlying button element.
82+
* **Important**: When `href` is provided, the component renders a `<Link>` with a `<div>` inside,
83+
* and the ref will not be forwarded. In this scenario, accessing the ref will return `null`.
84+
* If you need ref access, avoid using the `href` prop.
85+
*/
7186
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
7287
(
7388
{
@@ -169,7 +184,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
169184
<button
170185
ref={ref}
171186
// eslint-disable-next-line react/button-has-type
172-
type={htmlType}
187+
type={htmlType || 'button'}
173188
dir={direction}
174189
className={classes}
175190
disabled={disabled}

0 commit comments

Comments
 (0)