Skip to content

Commit 2a1cec7

Browse files
committed
Allow to add extra props on Button
1 parent 0737d8c commit 2a1cec7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Button.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ export namespace ButtonProps {
5454
export type AsAnchor = {
5555
linkProps: RegisteredLinkProps;
5656
onClick?: never;
57+
nativeButtonProps?: never;
5758
disabled?: never;
5859
type?: never;
5960
};
6061
export type AsButton = {
6162
linkProps?: never;
6263
onClick: React.MouseEventHandler<HTMLButtonElement>;
64+
nativeButtonProps?: Omit<
65+
React.DetailedHTMLProps<
66+
React.ButtonHTMLAttributes<HTMLButtonElement>,
67+
HTMLButtonElement
68+
>,
69+
"onClick"
70+
>;
6371
disabled?: boolean;
6472
/** Default "button" */
6573
type?: "button" | "submit" | "reset";
@@ -79,6 +87,7 @@ export const Button = memo(
7987
size = "medium",
8088
linkProps,
8189
onClick,
90+
nativeButtonProps,
8291
disabled,
8392
type,
8493
...rest
@@ -124,6 +133,7 @@ export const Button = memo(
124133
</Link>
125134
) : (
126135
<button
136+
{...nativeButtonProps}
127137
className={className}
128138
type={type}
129139
title={title}

stories/Button.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ const { meta, getStory } = getStoryFactory({
6262
"disabled": {
6363
"control": { "type": "boolean" }
6464
},
65+
"nativeButtonProps": {
66+
"description": `Can be used to attach extra props to the underlying native button.
67+
Example: \`{ "aria-controls": "fr-modal-1", onMouseEnter: event => {...} }\``,
68+
"control": { "type": null }
69+
},
6570
"children": {
71+
"description": "The label of the button",
6672
"control": { "type": "string" }
6773
}
6874
},

0 commit comments

Comments
 (0)