Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FieldCheckbox blur validation on Firefox #1384

Merged
merged 3 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ way to update this template, but currently, we follow a pattern:

## Upcoming version 2020-XX-XX

- [fix] Fix FieldCheckbox validation on blur event on Firefox.
[#1384](https://github.com/sharetribe/ftw-daily/pull/1384)

## [v7.0.0] 2020-11-17

This major release renames all the CSS files. If you have made custom components or customized
Expand Down
2 changes: 1 addition & 1 deletion src/components/FieldCheckbox/FieldCheckbox.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const FormComponent = props => (
handleSubmit(e);
}}
>
<FormSpy onChange={onChange} />
<FormSpy onChange={onChange} subscription={{ values: true, dirty: true }} />
<FieldCheckbox id="checkbox-id1" name="checkbox-group" label="option 1" value="option1" />
<FieldCheckbox id="checkbox-id2" name="checkbox-group" label="option 2" value="option2" />

Expand Down
27 changes: 20 additions & 7 deletions src/components/FieldCheckbox/FieldCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ const FieldCheckboxComponent = props => {
} = props;

const classes = classNames(rootClassName || css.root, className);
const checkboxProps = {
id,
className: css.input,
component: 'input',
type: 'checkbox',
...rest,

// This is a workaround for a bug in Firefox & React Final Form.
// https://github.com/final-form/react-final-form/issues/134
const handleOnChange = (input, event) => {
const { onBlur, onChange } = input;
onChange(event);
onBlur(event);
};

const successColorVariantMaybe = useSuccessColor
Expand All @@ -64,7 +65,19 @@ const FieldCheckboxComponent = props => {

return (
<span className={classes}>
<Field {...checkboxProps} />
<Field type="checkbox" {...rest}>
{props => {
const input = props.input;
return (
<input
id={id}
className={css.input}
{...input}
onChange={event => handleOnChange(input, event)}
/>
);
}}
</Field>
<label htmlFor={id} className={css.label}>
<span className={css.checkboxWrapper}>
<IconCheckbox className={svgClassName} {...successColorVariantMaybe} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const formComponent = country => props => (
handleSubmit(e);
}}
>
<FormSpy onChange={onChange} />
<FormSpy onChange={onChange} subscription={{ values: true, dirty: true }} />
<FieldCheckboxGroup {...componentProps} />

<Button style={{ marginTop: 24 }} type="submit" disabled={submitDisabled}>
Expand Down