From 0a4a4be27f06af563a80ddfde0905be64e786667 Mon Sep 17 00:00:00 2001 From: Kerry Money Date: Tue, 8 Dec 2020 12:34:45 -0500 Subject: [PATCH 1/5] [EuiButtonGroup] pass a type of button when rendering a button for button group button --- src/components/button/button.tsx | 1 + .../__snapshots__/button_group.test.tsx.snap | 58 +++++++++++++++++++ .../button_group/button_group_button.tsx | 4 ++ 3 files changed, 63 insertions(+) diff --git a/src/components/button/button.tsx b/src/components/button/button.tsx index 7a07d67cf99..9d2ec795af1 100644 --- a/src/components/button/button.tsx +++ b/src/components/button/button.tsx @@ -119,6 +119,7 @@ export interface EuiButtonProps extends EuiButtonContentProps, CommonProps { */ contentProps?: EuiButtonContentType; style?: CSSProperties; + type?: 'button' | 'submit' | 'reset'; } export type EuiButtonDisplayProps = EuiButtonProps & diff --git a/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap b/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap index 0db6d7464d8..0dff8d66119 100644 --- a/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap +++ b/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap @@ -18,6 +18,7 @@ exports[`EuiButtonGroup button props buttonSize compressed is rendered for multi class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small testClass1 testClass2" data-test-subj="test subject string" id="button00" + type="button" > = ({ @@ -70,6 +72,7 @@ export const EuiButtonGroupButton: FunctionComponent = ({ size, value, type = 'button', + buttonType = 'button', ...rest }) => { // Force element to be a button if disabled @@ -100,6 +103,7 @@ export const EuiButtonGroupButton: FunctionComponent = ({ ...elementProps, id, isSelected, + type: buttonType, onClick: () => onChange(id), }; } From 9fa7e7fa360be954d97a40bda00b73a0d15091ec Mon Sep 17 00:00:00 2001 From: Kerry Money Date: Tue, 8 Dec 2020 13:09:53 -0500 Subject: [PATCH 2/5] [EuiButtonGroup]: add some autodoc comments to new props --- src/components/button/button.tsx | 3 +++ src/components/button/button_group/button_group.tsx | 5 +++++ src/components/button/button_group/button_group_button.tsx | 2 -- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/button/button.tsx b/src/components/button/button.tsx index 9d2ec795af1..f189362adfc 100644 --- a/src/components/button/button.tsx +++ b/src/components/button/button.tsx @@ -119,6 +119,9 @@ export interface EuiButtonProps extends EuiButtonContentProps, CommonProps { */ contentProps?: EuiButtonContentType; style?: CSSProperties; + /** + * The type of the underlying HTML button + */ type?: 'button' | 'submit' | 'reset'; } diff --git a/src/components/button/button_group/button_group.tsx b/src/components/button/button_group/button_group.tsx index 6702a364b1c..a5217541d05 100644 --- a/src/components/button/button_group/button_group.tsx +++ b/src/components/button/button_group/button_group.tsx @@ -42,6 +42,11 @@ export interface EuiButtonGroupOptionProps * The value of the radio input. */ value?: any; + + /** + * The type of the underlying HTML button + */ + buttonType?: 'button' | 'submit' | 'reset'; } export type EuiButtonGroupProps = CommonProps & { diff --git a/src/components/button/button_group/button_group_button.tsx b/src/components/button/button_group/button_group_button.tsx index 4975e47a697..814138d8e12 100644 --- a/src/components/button/button_group/button_group_button.tsx +++ b/src/components/button/button_group/button_group_button.tsx @@ -56,8 +56,6 @@ type Props = EuiButtonGroupOptionProps & { * Inherit from EuiButtonGroup */ onChange: EuiButtonGroupProps['onChange']; - - buttonType?: 'button' | 'submit' | 'reset'; }; export const EuiButtonGroupButton: FunctionComponent = ({ From 5947e1ebde3c9fce328ea27b9dc370b8e6841222 Mon Sep 17 00:00:00 2001 From: Kerry Money Date: Tue, 8 Dec 2020 13:17:54 -0500 Subject: [PATCH 3/5] [EuiButtonGroup]: add changes to change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afb055cb2a2..d2856c19556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Added `!default` to SASS variables of `EuiCollapsibleNav` ([#4335](https://github.com/elastic/eui/pull/4335)) - Fixed `EuiDataGrid` column property `displayAsText`. Column headers prefer `displayAsText` over `id`; `display` still takes precedence. If provided, the filter in the sort-popover will search against `displayAsText` instead of `id`. ([#4351](https://github.com/elastic/eui/pull/4351)) - Fixed propagation of `esc` key presses closing parent popovers ([#4336](https://github.com/elastic/eui/pull/4336)) +- Fixed autosubmit bug in button `EuiButtonGroup` by adding an optional `type` prop for `EuiButtonGroupOption` and `EuiButton` ([#4368](https://github.com/elastic/eui/pull/4368)). **Theme: Amsterdam** From 0157521562d16ac37306f58233b15d28a43dc3cf Mon Sep 17 00:00:00 2001 From: Kerry Money Date: Tue, 8 Dec 2020 17:45:04 -0500 Subject: [PATCH 4/5] [EuiButtonGroup]: PR feedback: change the type attribute to element; add type attribute to button content instead of in both button and button group option --- src/components/button/button.tsx | 4 ---- src/components/button/button_content.tsx | 5 +++++ src/components/button/button_group/button_group.tsx | 7 +------ .../button/button_group/button_group_button.tsx | 12 ++++++------ 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/components/button/button.tsx b/src/components/button/button.tsx index f189362adfc..7a07d67cf99 100644 --- a/src/components/button/button.tsx +++ b/src/components/button/button.tsx @@ -119,10 +119,6 @@ export interface EuiButtonProps extends EuiButtonContentProps, CommonProps { */ contentProps?: EuiButtonContentType; style?: CSSProperties; - /** - * The type of the underlying HTML button - */ - type?: 'button' | 'submit' | 'reset'; } export type EuiButtonDisplayProps = EuiButtonProps & diff --git a/src/components/button/button_content.tsx b/src/components/button/button_content.tsx index 525f1b8dc17..2fc3e5a61c0 100644 --- a/src/components/button/button_content.tsx +++ b/src/components/button/button_content.tsx @@ -58,6 +58,11 @@ export interface EuiButtonContentProps extends CommonProps { ref?: Ref; 'data-text'?: string; }; + + /** + * The type of the underlying HTML button + */ + type?: 'button' | 'submit' | 'reset'; } export const EuiButtonContent: FunctionComponent< diff --git a/src/components/button/button_group/button_group.tsx b/src/components/button/button_group/button_group.tsx index a5217541d05..5cd3d59a463 100644 --- a/src/components/button/button_group/button_group.tsx +++ b/src/components/button/button_group/button_group.tsx @@ -42,11 +42,6 @@ export interface EuiButtonGroupOptionProps * The value of the radio input. */ value?: any; - - /** - * The type of the underlying HTML button - */ - buttonType?: 'button' | 'submit' | 'reset'; } export type EuiButtonGroupProps = CommonProps & { @@ -184,7 +179,7 @@ export const EuiButtonGroup: FunctionComponent = ({ name={nameIfSingle} isDisabled={isDisabled} {...(option as EuiButtonGroupOptionProps)} - type={typeIsSingle ? 'label' : 'button'} + element={typeIsSingle ? 'label' : 'button'} isSelected={ typeIsSingle ? option.id === idSelected diff --git a/src/components/button/button_group/button_group_button.tsx b/src/components/button/button_group/button_group_button.tsx index 814138d8e12..de7e477d8a5 100644 --- a/src/components/button/button_group/button_group_button.tsx +++ b/src/components/button/button_group/button_group_button.tsx @@ -27,7 +27,7 @@ type Props = EuiButtonGroupOptionProps & { /** * Element to display based on single or multi */ - type: 'button' | 'label'; + element: 'button' | 'label'; /** * Styles the selected button to look selected (usually with `fill`) */ @@ -69,16 +69,16 @@ export const EuiButtonGroupButton: FunctionComponent = ({ onChange, size, value, + element = 'button', type = 'button', - buttonType = 'button', ...rest }) => { // Force element to be a button if disabled - const element = isDisabled ? 'button' : type; + const el = isDisabled ? 'button' : element; let elementProps = {}; let singleInput; - if (element === 'label') { + if (el === 'label') { elementProps = { ...elementProps, htmlFor: id, @@ -101,7 +101,7 @@ export const EuiButtonGroupButton: FunctionComponent = ({ ...elementProps, id, isSelected, - type: buttonType, + type, onClick: () => onChange(id), }; } @@ -125,7 +125,7 @@ export const EuiButtonGroupButton: FunctionComponent = ({ Date: Wed, 9 Dec 2020 10:40:47 -0500 Subject: [PATCH 5/5] Move `type` back to EuiButtonGroupOption And added a test for changing it --- CHANGELOG.md | 3 +- src/components/button/button_content.tsx | 5 -- .../__snapshots__/button_group.test.tsx.snap | 56 +++++++++---------- .../button/button_group/button_group.test.tsx | 10 +++- .../button/button_group/button_group.tsx | 4 ++ 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2856c19556..a916542cf50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,7 @@ - Added `!default` to SASS variables of `EuiCollapsibleNav` ([#4335](https://github.com/elastic/eui/pull/4335)) - Fixed `EuiDataGrid` column property `displayAsText`. Column headers prefer `displayAsText` over `id`; `display` still takes precedence. If provided, the filter in the sort-popover will search against `displayAsText` instead of `id`. ([#4351](https://github.com/elastic/eui/pull/4351)) - Fixed propagation of `esc` key presses closing parent popovers ([#4336](https://github.com/elastic/eui/pull/4336)) -- Fixed autosubmit bug in button `EuiButtonGroup` by adding an optional `type` prop for `EuiButtonGroupOption` and `EuiButton` ([#4368](https://github.com/elastic/eui/pull/4368)). - +- Fixed form submit bug in `EuiButtonGroup` by adding an optional `type` prop for `EuiButtonGroupOption` ([#4368](https://github.com/elastic/eui/pull/4368)) **Theme: Amsterdam** diff --git a/src/components/button/button_content.tsx b/src/components/button/button_content.tsx index 2fc3e5a61c0..525f1b8dc17 100644 --- a/src/components/button/button_content.tsx +++ b/src/components/button/button_content.tsx @@ -58,11 +58,6 @@ export interface EuiButtonContentProps extends CommonProps { ref?: Ref; 'data-text'?: string; }; - - /** - * The type of the underlying HTML button - */ - type?: 'button' | 'submit' | 'reset'; } export const EuiButtonContent: FunctionComponent< diff --git a/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap b/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap index 0dff8d66119..0d2dba2a90b 100644 --- a/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap +++ b/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap @@ -59,7 +59,7 @@ exports[`EuiButtonGroup button props buttonSize compressed is rendered for multi class="euiButtonGroupButton euiButtonGroupButton--text euiButtonGroupButton--small euiButtonGroupButton-isDisabled" disabled="" id="button02" - type="button" + type="submit" > = [ @@ -30,7 +35,7 @@ const SIZES: Array = [ 'compressed', ]; -const options = [ +const options: EuiButtonGroupOptionProps[] = [ { id: 'button00', label: 'Option one', @@ -47,6 +52,7 @@ const options = [ label: 'Option three', iconType: 'bolt', isDisabled: true, + type: 'submit', }, ]; diff --git a/src/components/button/button_group/button_group.tsx b/src/components/button/button_group/button_group.tsx index 5cd3d59a463..8ec71fd9f6a 100644 --- a/src/components/button/button_group/button_group.tsx +++ b/src/components/button/button_group/button_group.tsx @@ -42,6 +42,10 @@ export interface EuiButtonGroupOptionProps * The value of the radio input. */ value?: any; + /** + * The type of the underlying HTML button + */ + type?: 'button' | 'submit' | 'reset'; } export type EuiButtonGroupProps = CommonProps & {