Skip to content

Commit faf8088

Browse files
Elliotmdodgelooker
andauthored
FieldCheckboxGroup: Apply proper error state styles (#1622)
* Added error styling to FieldCheckboxGroup when validationMessage.type is "error" * Added example of validation styling for FieldCheckboxGroup to playground * Reverted changes to InputText.tsx * Utilized inputTextValidation css helper function to get validation css for FieldCheckboxGroup * Added CHANGELOG entry * Reverting playground changes * Reverted changes to InputText.tsx * Added FieldCheckboxGroup story * Revered changes to Field.tsx * Removed FieldCheckboxGroup.story file * Used validationMessage prop to trigger error state styles on child FieldCheckboxes * Converted CheckboxGroup.stories to utilize Template.bind({}) * Moved FieldCheckboxGroup.stories file into the components package - For image snapshot purposes * Added FieldCheckbox image snapshots * Update packages/components/src/Form/Fields/FieldCheckboxGroup/FieldCheckboxGroup.story.tsx Co-authored-by: mdodgelooker <[email protected]> * Moved Forms/CheckboxGroup to their own dir * Deleted "CheckboxGroup" snapshots * Moved CheckboxGroup snapshots to FieldCheckboxGroup dir Co-authored-by: mdodgelooker <[email protected]>
1 parent d31a77c commit faf8088

File tree

12 files changed

+49
-64
lines changed

12 files changed

+49
-64
lines changed

packages/components/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020

2121
### Fixed
2222

23+
- `FieldCheckboxGroup` now sets `border-color` of child checkboxes to "critical" when validationMessage.type is equal to 'error'
2324
- `Select` on a mobile device or with "tap to click" on a touch pad reopens immediately after clicking on an option
2425
- `Select` options not being announced in a screen reader on keyboard navigation
2526
- Controlled `Select` losing focus if there's delay between `onChange` and `value` update
18.7 KB
Loading
18.1 KB
Loading
12 KB
Loading
20.1 KB
Loading
10.4 KB
Loading
18.8 KB
Loading

packages/components/src/Form/Fields/FieldCheckbox/FieldCheckbox.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ const FieldCheckboxLayout = forwardRef(
4949
{...omitFieldProps(props)}
5050
aria-describedby={`${id}-describedby`}
5151
id={id}
52-
validationType={validationMessage && validationMessage.type}
52+
validationType={
53+
(validationMessage && validationMessage.type) ||
54+
props.validationType
55+
}
5356
ref={ref}
5457
/>
5558
</FieldInline>

storybook/src/Forms/CheckboxGroup.stories.tsx renamed to packages/components/src/Form/Fields/FieldCheckboxGroup/FieldCheckboxGroup.story.tsx

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
*/
2626

2727
import React from 'react'
28-
import { FieldCheckboxGroup } from '@looker/components'
28+
import { Story } from '@storybook/react/types-6-0'
29+
import {
30+
FieldCheckboxGroup,
31+
FieldCheckboxGroupProps,
32+
} from './FieldCheckboxGroup'
2933

3034
export default {
31-
title: 'Forms/CheckboxGroup',
35+
title: 'FieldCheckboxGroup',
3236
}
3337

3438
const options = [
@@ -87,72 +91,51 @@ const options = [
8791

8892
const defaultValueCheckbox = ['swiss', 'cheddar']
8993

90-
export const Basic = () => (
94+
const Template: Story<FieldCheckboxGroupProps> = (args) => (
9195
<FieldCheckboxGroup
96+
{...args}
9297
defaultValue={defaultValueCheckbox}
9398
label="Cheeses"
9499
description="Pick all your cheeses"
95100
options={options}
96101
/>
97102
)
98103

99-
export const Disabled = () => (
100-
<FieldCheckboxGroup
101-
defaultValue={defaultValueCheckbox}
102-
label="Cheeses"
103-
description="Pick all your cheeses"
104-
options={options}
105-
disabled
106-
/>
107-
)
104+
export const Basic = Template.bind({})
105+
Basic.args = {}
108106

109-
export const Required = () => (
110-
<FieldCheckboxGroup
111-
defaultValue={defaultValueCheckbox}
112-
label="Cheeses"
113-
inline
114-
description="Pick all your cheeses"
115-
options={options}
116-
/>
117-
)
107+
export const Disabled = Template.bind({})
108+
Disabled.args = {
109+
disabled: true,
110+
}
118111

119-
export const Inline = () => (
120-
<FieldCheckboxGroup
121-
defaultValue={defaultValueCheckbox}
122-
label="Cheeses"
123-
inline
124-
description="Pick all your cheeses"
125-
options={options}
126-
/>
127-
)
112+
export const Required = Template.bind({})
113+
Required.args = {
114+
required: true,
115+
}
128116

129-
export const Error = () => (
130-
<FieldCheckboxGroup
131-
defaultValue={defaultValueCheckbox}
132-
label="Cheeses"
133-
validationMessage={{
134-
message: 'Select at least 1 cheese',
135-
type: 'error',
136-
}}
137-
description="Pick all your cheeses"
138-
options={options}
139-
/>
140-
)
117+
export const Inline = Template.bind({})
118+
Inline.args = {
119+
inline: true,
120+
}
141121

142-
export const ErrorInline = () => (
143-
<FieldCheckboxGroup
144-
defaultValue={defaultValueCheckbox}
145-
label="Cheeses"
146-
inline
147-
required
148-
validationMessage={{
149-
message: 'Select at least 1 cheese',
150-
type: 'error',
151-
}}
152-
description="Pick all your cheeses"
153-
options={options}
154-
/>
155-
)
122+
export const Error = Template.bind({})
123+
Error.args = {
124+
validationMessage: {
125+
message: 'Select at least 1 cheese',
126+
type: 'error',
127+
},
128+
}
129+
130+
export const ErrorInline = Template.bind({})
131+
ErrorInline.args = {
132+
inline: true,
133+
required: true,
134+
validationMessage: {
135+
message: 'Select at least 1 cheese',
136+
type: 'error',
137+
},
138+
}
156139

157140
// export const Controlled = () => 'TODO'
158141

packages/components/src/Form/Fields/FieldCheckboxGroup/FieldCheckboxGroup.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ const FieldCheckboxGroupLayout: FC<FieldCheckboxGroupProps> = ({
4949
const id = useID(propsID)
5050

5151
return (
52-
<Field
53-
{...pickFieldProps(props)}
54-
validationMessage={validationMessage}
55-
id={id}
56-
>
52+
<Field {...pickFieldProps(props)} id={id}>
5753
<CheckboxGroup
5854
{...omitFieldProps(props)}
5955
aria-describedby={`${id}-describedby`}
@@ -62,6 +58,7 @@ const FieldCheckboxGroupLayout: FC<FieldCheckboxGroupProps> = ({
6258
inline={props.inline || inputsInline}
6359
name={name || id}
6460
options={options}
61+
validationType={validationMessage && validationMessage.type}
6562
value={value}
6663
/>
6764
</Field>

0 commit comments

Comments
 (0)