-
Notifications
You must be signed in to change notification settings - Fork 3
Updates to ChoiceBox; Checkbox, Radio components #1174
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
Conversation
| const fieldGridItemProps = { | ||
| ...gridItemProps, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, any reason to spread this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope 🤷♂️
| ) | ||
| } | ||
|
|
||
| Radio.styles = containerStyles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for re-use? I had no idea typescript would let you do this without declaring the property on Radio beforehand. Interesting.
Suggestion: wrap it in css() from import { css } from "@emotion/react". That will allow it to work with either the object or template literal syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. It won't work outside of Emotion though if we need it as plain css, which I guess we don't (ie. can't be interpolated - its toString() method returns a warning message).
| const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
| setChecked(event.target.checked) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Suggestion: ** call action("changed")(event)
from import { action } from "@storybook/addon-actions"
| const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
| setChecked(event.target.checked) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Suggestion: ** call action("changed")(event)
from import { action } from "@storybook/addon-actions"
| const target = event.target as HTMLInputElement | ||
| if (target.checked) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Suggestion: ** call action("changed")(event)
from import { action } from "@storybook/addon-actions"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I achieved the same with this on the meta:
argTypes: {
onChange: {
action: "change"
}
}
and calling props.onChange?.(event) in our StateWrapper.
| const [checked, setChecked] = useState(!!props.checked) | ||
|
|
||
| const handleChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
| setChecked(event.target.checked) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Suggestion: ** call action("changed")(event)
from import { action } from "@storybook/addon-actions"
| return ( | ||
| <ChoiceBoxField | ||
| type="checkbox" | ||
| isChecked={(choice) => values?.indexOf(choice.value) !== -1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values?.includes(...) 🤷
| ) | ||
| } | ||
|
|
||
| export { ChoiceBoxField, CheckboxChoiceBoxField, RadioChoiceBoxField } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My inclination would be to not export ChoiceBoxField, at least for now.
May also want to add a docstring to to ChoiceBoxField along lines of
/**
* Prefer using `CheckboxChoiceBoxField` or `RadioChoiceBoxField` instead of
* this component, where possible.
*/
The only case I can think of where you'd use ChoiceBoxField directly would be if you needed a checkbox with the "partially checked" state?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. We need the wrapping components for the different isChecked workings.
The naming Field isn't great here. Technically they're fieldsets. Thoughts on RadioChoiceBoxFieldset or even RadioChoiceBoxGrid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO... "Field" is fine. "Field" is not a technical HTML term as far as I know. (In contrast to fieldset—please educate me if I am mistaken!). *I.e., I don't equate "field" with "single input element".
RadioGroup is a good name for the radio version (after `role="radiogroup"—which we could add, but isn't really necessary afaik since we are using native radio elements). But there's not checkboxgroup role.
Leaving *Field seems fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see it as an individual form field (ie. an input) as opposed to a fieldset containing multiple - the ChoiceBoxField container element is an html fieldset.
| <FormLabel component="legend" sx={{ width: "100%" }}> | ||
| {label} | ||
| </FormLabel> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few overall comments here:
-
It would be nice to be able to support
requiredand an error message. -
I'm not sure what FormControl gives us. My understanding is that MUI uses this to wrap its inputs to manage some internal state. See https://mui.com/base-ui/react-form-control/. I chose not to use it for our TextField, and instead we have
FormFieldWrapperinFormHelpers.- That said, FormFieldWrapper isn't directly directly usable here. It's expecting a single input, like select or text.
- That said, the error message / description / required components in FormHelpers might be helpful.
-
I don't think we have very explicit component designs for
ChoiceBoxField, but it seems to me it should match https://www.figma.com/design/Eux3guSenAFVvNHGi1Y9Wm/MIT-Design-System?node-id=4345-87576&m=dev :
I.e., the legend currently doesn't have the style we want.
- We do have explicit field designs for text input. See https://www.figma.com/design/Eux3guSenAFVvNHGi1Y9Wm/MIT-Design-System?node-id=104-1582&m=dev
My inclination for actionable steps right now:
- Make title match profile page style (i.e., subtitle2, which is what the textfield and selectfield labels use, too)
- add spot for overall description + error message, using styles from FormHelpers. You could alter FormFieldWrapper and use it, if you see fit. But the spacing between legend and input is also a little different, I think. 8px not 4px.
| interface ChoiceBoxFieldProps extends BaseChoiceBoxFieldProps { | ||
| type: ChoiceBoxProps["type"] | ||
| name?: string | ||
| isChecked: (choice: ChoiceBoxChoice) => boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: I can imagine isDisabled would also be useful, but I don't think we need to add it now.
ChristopherChudzicki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested change is the alignment issue.
|
These changes also pushed:
|
ChristopherChudzicki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍

What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/4661
Description (What does it do?)
Updates the styles and hover states for the ChoiceBox and its field grid.
Also:
Screenshots (if appropriate):
How can this be tested?