Skip to content

Commit

Permalink
[env:jsx] Add HTMLButtonElement definition
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalduez committed May 25, 2023
1 parent e278f69 commit 4d91c93
Show file tree
Hide file tree
Showing 2 changed files with 198 additions and 93 deletions.
238 changes: 164 additions & 74 deletions definitions/environments/jsx/flow_v0.83.x-/jsx.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
/**
* https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#list_of_global_attributes
*/
declare type jsx$HTMLElement = {
declare type jsx$HTMLElement = {
/**
* Specifies a shortcut key to activate/focus an element
*/
accessKey?: string,
/**
* Specifies one or more classnames for an element (refers to a class in a style sheet)
*/
className?: string,
/**
* Specifies whether the content of an element is editable or not
*/
contentEditable?: string,
/**
* Specifies meta tag for application testing or querying
*/
'data-testid'?: string,
/**
* Specifies the text direction for the content in an element
*/
dir?: string,
/**
* Specifies whether an element is draggable or not
*/
draggable?: string,
/**
* Specifies that an element is not yet, or is no longer, relevant
*/
hidden?: boolean | '' | 'hidden' | 'until-found',
/**
* Specifies a unique id for an element
*/
id?: string,
/**
* Specify that a standard HTML element should behave like a defined custom
* built-in element
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is
*/
is?: string,
/**
* Specifies the language of the element's content
*/
lang?: string,
/*
* Roles define the semantic meaning of content, allowing screen readers and
* other tools to present and support interaction with an object in a way that
* is consistent with user expectations of that type of object.
*/
role?: string,
/*
* Assigns a slot in a shadow DOM shadow tree to an element: An element with a
* slot attribute is assigned to the slot created by the <slot> element whose
* name attribute's value matches that slot attribute's value.
*/
slot?: string,
/**
* Specifies whether the element is to have its spelling and grammar checked or not
*/
spellCheck?: string,
/*
* Contains CSS styling declarations to be applied to the element.
*/
style?: { +[string]: string | number, ... },
/**
* Specifies the tabbing order of an element
*/
tabIndex?: string,
/**
* Specifies extra information about an element
*/
title?: string,
/**
* Specifies whether the content of an element should be translated or not
*/
translate?: string,
...
accessKey?: string,
/**
* Specifies one or more classnames for an element (refers to a class in a style sheet)
*/
className?: string,
/**
* Specifies whether the content of an element is editable or not
*/
contentEditable?: string,
/**
* Specifies meta tag for application testing or querying
*/
'data-testid'?: string,
/**
* Specifies the text direction for the content in an element
*/
dir?: string,
/**
* Specifies whether an element is draggable or not
*/
draggable?: string,
/**
* Specifies that an element is not yet, or is no longer, relevant
*/
hidden?: boolean | '' | 'hidden' | 'until-found',
/**
* Specifies a unique id for an element
*/
id?: string,
/**
* Specify that a standard HTML element should behave like a defined custom
* built-in element
* @see https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is
*/
is?: string,
/**
* Specifies the language of the element's content
*/
lang?: string,
/*
* Roles define the semantic meaning of content, allowing screen readers and
* other tools to present and support interaction with an object in a way that
* is consistent with user expectations of that type of object.
*/
role?: string,
/*
* Assigns a slot in a shadow DOM shadow tree to an element: An element with a
* slot attribute is assigned to the slot created by the <slot> element whose
* name attribute's value matches that slot attribute's value.
*/
slot?: string,
/**
* Specifies whether the element is to have its spelling and grammar checked or not
*/
spellCheck?: string,
/*
* Contains CSS styling declarations to be applied to the element.
*/
style?: { +[string]: string | number, ... },
/**
* Specifies the tabbing order of an element
*/
tabIndex?: string,
/**
* Specifies extra information about an element
*/
title?: string,
/**
* Specifies whether the content of an element should be translated or not
*/
translate?: string,
...
};

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ declare type jsx$HTMLInputElement = {
/**
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#attributes
*/
declare type jsx$HTMLTextAreaElement = {
declare type jsx$HTMLTextAreaElement = {
...jsx$HTMLElement,
/**
* This attribute indicates whether the value of the control can be automatically completed by the browser. Possible values are:
Expand Down Expand Up @@ -199,3 +199,93 @@ declare type jsx$HTMLInputElement = {
wrap?: 'hard' | 'soft' | 'off',
...
};

/**
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement
*/
declare type jsx$HTMLButtonElement = {
...jsx$HTMLElement,
/**
* This Boolean attribute specifies that the button should have input focus when the page loads. Only one element in a document can have this attribute.
*/
autofocus?: boolean,
/**
* This Boolean attribute prevents the user from interacting with the button: it cannot be pressed or focused.
*/
disabled?: boolean,
/**
* The <form> element to associate the button with (its form owner). The value of this attribute must be the id of a <form> in the same document. (If this attribute is not set, the <button> is associated with its ancestor <form> element, if any.)
* This attribute lets you associate <button> elements to <form>s anywhere in the document, not just inside a <form>. It can also override an ancestor <form> element.
*/
form?: string,
/**
The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner. Does nothing if there is no form owner.
*/
formaction?: string,
/**
* If the button is a submit button (it's inside/associated with a <form> and doesn't have type="button"), specifies how to encode the form data that is submitted. Possible values:
*
* application/x-www-form-urlencoded: The default if the attribute is not used.
* multipart/form-data: Used to submit <input> elements with their type attributes set to file.
* text/plain: Specified as a debugging aid; shouldn't be used for real form submission.
*
* If this attribute is specified, it overrides the enctype attribute of the button's form owner.
*/
formenctype?:
| 'application/x-www-form-urlencoded'
| 'multipart/form-data'
| 'text/plain',
/**
* If the button is a submit button (it's inside/associated with a <form> and doesn't have type="button"), this attribute specifies the HTTP method used to submit the form. Possible values:
*
* post: The data from the form are included in the body of the HTTP request when sent to the server. Use when the form contains information that shouldn't be public, like login credentials.
* get: The form data are appended to the form's action URL, with a ? as a separator, and the resulting URL is sent to the server. Use this method when the form has no side effects, like search forms.
*
* If specified, this attribute overrides the method attribute of the button's form owner.
*/
formmethod?: 'post' | 'get',
/**
* If the button is a submit button, this Boolean attribute specifies that the form is not to be validated when it is submitted. If this attribute is specified, it overrides the novalidate attribute of the button's form owner.
* This attribute is also available on <input type="image"> and <input type="submit"> elements.
*/
formnovalidate?: boolean,
/**
* If the button is a submit button, this attribute is an author-defined name or standardized, underscore-prefixed keyword indicating where to display the response from submitting the form. This is the name of, or keyword for, a browsing context (a tab, window, or <iframe>). If this attribute is specified, it overrides the target attribute of the button's form owner. The following keywords have special meanings:
*
* _self: Load the response into the same browsing context as the current one. This is the default if the attribute is not specified.
* _blank: Load the response into a new unnamed browsing context — usually a new tab or window, depending on the user's browser settings.
* _parent: Load the response into the parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.
* _top: Load the response into the top-level browsing context (that is, the browsing context that is an ancestor of the current one, and has no parent). If there is no parent, this option behaves the same way as _self.
*/
formtarget?: '_self' | '_blank' | '_parent' | '_top',
/**
* The name of the button, submitted as a pair with the button's value as part of the form data, when that button is used to submit the form.
*/
name?: string,
/**
* Turns a <button> element into a popover control button; takes the ID of the popover element to control as its value. See the Popover API landing page for more details.
*/
popovertarget?: string,
/**
* Specifies the the action to be performed on a popover element being controlled by a control <button>. Possible values are:
*
* hide: The button will hide a shown popover. If you try to hide an already hidden popover, no action will be taken.
* show: The button will show a hidden popover. If you try to show an already showing popover, no action will be taken.
* toggle: The button will toggle a popover between showing and hidden. If the popover is hidden, it will be shown; if the popover is showing, it will be hidden. If popovertargetaction is omitted, "toggle" is the default action that will be performed by the control button.
*/
popovertargetaction?: 'hide' | 'show' | 'toggle',
/**
* The default behavior of the button. Possible values are:
*
* submit: The button submits the form data to the server. This is the default if the attribute is not specified for buttons associated with a <form>, or if the attribute is an empty or invalid value.
* reset: The button resets all the controls to their initial values, like <input type="reset">. (This behavior tends to annoy users.)
* button: The button has no default behavior, and does nothing when pressed by default. It can have client-side scripts listen to the element's events, which are triggered when the events occur.
*
*/
type?: 'submit' | 'reset' | 'button',
/**
* Defines the value associated with the button's name when it's submitted with the form data. This value is passed to the server in params when the form is submitted using this button.
*/
value?: string,
...
};
53 changes: 34 additions & 19 deletions definitions/environments/jsx/flow_v0.83.x-/test_jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ describe('jsx', () => {
bar,
...otherProps
}: Props) => {
return (
<input foo={foo} {...otherProps} />
);
return <input foo={foo} {...otherProps} />;
};
});

Expand All @@ -75,19 +73,14 @@ describe('jsx', () => {
type: jsx$HTMLInputElement$Type | 'extra',
|};

const Input = ({
type,
...otherProps
}: Props) => {
return (
<input type={type} {...otherProps} />
);
const Input = ({ type, ...otherProps }: Props) => {
return <input type={type} {...otherProps} />;
};

const a = <Input type="text" />
const b = <Input type="extra" />
const a = <Input type="text" />;
const b = <Input type="extra" />;
// $FlowExpectedError[incompatible-type]
const c = <Input type="random" />
const c = <Input type="random" />;
});
});

Expand All @@ -104,16 +97,38 @@ describe('jsx', () => {
bar,
...otherProps
}: Props) => {
return (
<textarea foo={foo} {...otherProps} />
);
return <textarea foo={foo} {...otherProps} />;
};

<TextArea autoComplete="on" />;
// $FlowExpectedError[incompatible-type]
<TextArea autoComplete={true} />;
// $FlowExpectedError[incompatible-type]
<TextArea autoComplete="yes" />;
});
});

describe('HTMLButtonElement', () => {
it('has button props', () => {
type Props = {|
...$Exact<jsx$HTMLButtonElement>,
foo?: string,
|};

const Button = ({
foo,
// $FlowExpectedError[prop-missing]
bar,
...otherProps
}: Props) => {
return <button foo={foo} {...otherProps} />;
};

(<TextArea autoComplete="on" />);
<Button type="button" />;
// $FlowExpectedError[incompatible-type]
(<TextArea autoComplete={true} />);
<Button type={true} />;
// $FlowExpectedError[incompatible-type]
(<TextArea autoComplete="yes" />);
<Button type="fail" />;
});
});
});

0 comments on commit 4d91c93

Please sign in to comment.