11
11
*/
12
12
import { AriaButtonProps , mergeProps , useButton , useFocusRing , useHover } from 'react-aria' ;
13
13
import { ContextValue , RenderProps , SlotProps , useContextProps , useRenderProps } from './utils' ;
14
+ import { filterDOMProps } from '@react-aria/utils' ;
14
15
import React , { createContext , ForwardedRef , forwardRef } from 'react' ;
15
16
16
17
export interface ButtonRenderProps {
@@ -41,11 +42,37 @@ export interface ButtonRenderProps {
41
42
isDisabled : boolean
42
43
}
43
44
44
- export interface ButtonProps extends Omit < AriaButtonProps , 'children' | 'href' | 'target' | 'rel' | 'elementType' > , SlotProps , RenderProps < ButtonRenderProps > { }
45
+ export interface ButtonProps extends Omit < AriaButtonProps , 'children' | 'href' | 'target' | 'rel' | 'elementType' > , SlotProps , RenderProps < ButtonRenderProps > {
46
+ /**
47
+ * The <form> element to associate the button with.
48
+ * The value of this attribute must be the id of a <form> in the same document.
49
+ */
50
+ form ?: string ,
51
+ /**
52
+ * The URL that processes the information submitted by the button.
53
+ * Overrides the action attribute of the button's form owner.
54
+ */
55
+ formAction ?: string ,
56
+ /** Indicates how to encode the form data that is submitted. */
57
+ formEncType ?: string ,
58
+ /** Indicates the HTTP method used to submit the form. */
59
+ formMethod ?: string ,
60
+ /** Indicates that the form is not to be validated when it is submitted. */
61
+ formNoValidate ?: boolean ,
62
+ /** Overrides the target attribute of the button's form owner. */
63
+ formTarget ?: string ,
64
+ /** Submitted as a pair with the button's value as part of the form data. */
65
+ name ?: string ,
66
+ /** The value associated with the button's name when it's submitted with the form data. */
67
+ value ?: string
68
+ }
69
+
45
70
interface ButtonContextValue extends ButtonProps {
46
71
isPressed ?: boolean
47
72
}
48
73
74
+ const additionalButtonHTMLAttributes = new Set ( [ 'form' , 'formAction' , 'formEncType' , 'formMethod' , 'formNoValidate' , 'formTarget' , 'name' , 'value' ] ) ;
75
+
49
76
export const ButtonContext = createContext < ContextValue < ButtonContextValue , HTMLButtonElement > > ( { } ) ;
50
77
51
78
function Button ( props : ButtonProps , ref : ForwardedRef < HTMLButtonElement > ) {
@@ -62,6 +89,7 @@ function Button(props: ButtonProps, ref: ForwardedRef<HTMLButtonElement>) {
62
89
63
90
return (
64
91
< button
92
+ { ...filterDOMProps ( props , { propNames : additionalButtonHTMLAttributes } ) }
65
93
{ ...mergeProps ( buttonProps , focusProps , hoverProps ) }
66
94
{ ...renderProps }
67
95
ref = { ref }
0 commit comments