From 027708ec69d7f920252d8ab58054ded28b7b82d6 Mon Sep 17 00:00:00 2001 From: jxom Date: Thu, 14 Feb 2019 12:04:55 +1100 Subject: [PATCH] Add isFilled prop to Set; Make SelectMenu more form friendly --- src/Checkbox/Checkbox.tsx | 6 +- .../__snapshots__/FieldSet.test.tsx.snap | 9 +- .../__snapshots__/LayoutSet.test.tsx.snap | 18 ++-- src/Menu/MenuButton.tsx | 1 + src/Menu/MenuItem.tsx | 2 +- .../__snapshots__/Menu.test.tsx.snap | 22 +++++ src/SelectMenu/SelectMenu.tsx | 60 +++++++++--- src/Set/Set.mdx | 14 +++ src/Set/Set.tsx | 3 + .../__tests__/__snapshots__/Set.test.tsx.snap | 9 +- src/Set/styled.ts | 10 +- src/adaptors/fields.tsx | 97 +++++++++++++++++++ src/adaptors/formikField.tsx | 17 ---- src/adaptors/index.ts | 3 +- src/adaptors/reduxFormField.tsx | 17 ---- 15 files changed, 211 insertions(+), 77 deletions(-) create mode 100644 src/adaptors/fields.tsx delete mode 100644 src/adaptors/formikField.tsx delete mode 100644 src/adaptors/reduxFormField.tsx diff --git a/src/Checkbox/Checkbox.tsx b/src/Checkbox/Checkbox.tsx index 11d46c978..1d2877f8c 100644 --- a/src/Checkbox/Checkbox.tsx +++ b/src/Checkbox/Checkbox.tsx @@ -25,7 +25,7 @@ export type LocalCheckboxProps = { /** State of the checkbox. Can be any color in the palette. */ state?: string; /** Initial value of the checkbox */ - value?: string; + value?: boolean | string; /** Function to invoke when focus is lost */ onBlur?: React.FocusEventHandler; /** Function to invoke when checkbox has changed */ @@ -73,6 +73,7 @@ export const Checkbox: React.FunctionComponent = ({ name={name} state={state} type="checkbox" + // @ts-ignore value={value} /> @@ -96,7 +97,7 @@ export const checkboxPropTypes = { label: PropTypes.string, name: PropTypes.string, state: PropTypes.string, - value: PropTypes.string, + value: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), onBlur: PropTypes.func, onChange: PropTypes.func, onFocus: PropTypes.func @@ -122,5 +123,6 @@ export const checkboxDefaultProps = { }; Checkbox.defaultProps = checkboxDefaultProps; +// @ts-ignore const C: React.FunctionComponent = Checkbox; export default C; diff --git a/src/FieldSet/__tests__/__snapshots__/FieldSet.test.tsx.snap b/src/FieldSet/__tests__/__snapshots__/FieldSet.test.tsx.snap index 4c8c355eb..9f5256542 100644 --- a/src/FieldSet/__tests__/__snapshots__/FieldSet.test.tsx.snap +++ b/src/FieldSet/__tests__/__snapshots__/FieldSet.test.tsx.snap @@ -65,16 +65,13 @@ exports[`renders correctly for a basic field 1`] = ` display: -webkit-flex; display: -ms-flexbox; display: flex; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; - flex-wrap: wrap; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; -webkit-align-items: flex-start; -webkit-box-align: flex-start; -ms-flex-align: flex-start; align-items: flex-start; - -webkit-flex-direction: column; - -ms-flex-direction: column; - flex-direction: column; } .c1 > *:not(:last-child) { diff --git a/src/LayoutSet/__tests__/__snapshots__/LayoutSet.test.tsx.snap b/src/LayoutSet/__tests__/__snapshots__/LayoutSet.test.tsx.snap index 381b29012..c15ad1f99 100644 --- a/src/LayoutSet/__tests__/__snapshots__/LayoutSet.test.tsx.snap +++ b/src/LayoutSet/__tests__/__snapshots__/LayoutSet.test.tsx.snap @@ -23,16 +23,13 @@ exports[`renders correctly for a basic field 1`] = ` display: -webkit-flex; display: -ms-flexbox; display: flex; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; - flex-wrap: wrap; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; -webkit-align-items: flex-start; -webkit-box-align: flex-start; -ms-flex-align: flex-start; align-items: flex-start; - -webkit-flex-direction: column; - -ms-flex-direction: column; - flex-direction: column; } .c1 > *:not(:last-child) { @@ -44,16 +41,13 @@ exports[`renders correctly for a basic field 1`] = ` display: -webkit-flex; display: -ms-flexbox; display: flex; - -webkit-flex-wrap: wrap; - -ms-flex-wrap: wrap; - flex-wrap: wrap; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; -webkit-align-items: flex-start; -webkit-box-align: flex-start; -ms-flex-align: flex-start; align-items: flex-start; - -webkit-flex-direction: column; - -ms-flex-direction: column; - flex-direction: column; } .c8 > *:not(:last-child) { diff --git a/src/Menu/MenuButton.tsx b/src/Menu/MenuButton.tsx index 106f205cb..104831bc4 100644 --- a/src/Menu/MenuButton.tsx +++ b/src/Menu/MenuButton.tsx @@ -48,6 +48,7 @@ export class MenuButton extends React.Component { onKeyDown={this.handleKeyDown} {...context} {...props} + type="button" /> ); }; diff --git a/src/Menu/MenuItem.tsx b/src/Menu/MenuItem.tsx index 57f801395..f1b17957d 100644 --- a/src/Menu/MenuItem.tsx +++ b/src/Menu/MenuItem.tsx @@ -48,7 +48,7 @@ export class MenuItem extends React.Component { render = () => { const { children, icon, isDisabled, ...props } = this.props; return ( - <_MenuItem role="menuitem" disabled={isDisabled} {...props} onClick={this.handleClick}> + <_MenuItem role="menuitem" disabled={isDisabled} {...props} onClick={this.handleClick} type="button"> {icon && ( // @ts-ignore diff --git a/src/Menu/__tests__/__snapshots__/Menu.test.tsx.snap b/src/Menu/__tests__/__snapshots__/Menu.test.tsx.snap index 838f88e1d..98578c0ee 100644 --- a/src/Menu/__tests__/__snapshots__/Menu.test.tsx.snap +++ b/src/Menu/__tests__/__snapshots__/Menu.test.tsx.snap @@ -111,12 +111,14 @@ a.c3:hover { @@ -287,6 +289,7 @@ a.c5:hover { @@ -707,18 +712,21 @@ a.c15:hover { @@ -726,6 +734,7 @@ a.c15:hover { class="c14 c15 c17" color="danger" role="menuitem" + type="button" > Delete... @@ -746,6 +755,7 @@ a.c15:hover { class="c14 c15 c16 c21 " href="https://google.com" role="menuitem" + type="button" > Go to Google @@ -883,6 +893,7 @@ a.c3:hover { class="c3 c4" disabled="" role="menuitem" + type="button" >