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

update FormGroup and InputLabel to support fieldset and legend #632

Merged

Conversation

jasonbasuil
Copy link
Collaborator

@jasonbasuil jasonbasuil commented May 25, 2022

closes #631

Continuing from my initial PR-616, I think this could possibly be one / easiest? path forward to supporting <fieldset> and <legend> with our existing FormGroup with an initial cutover in order to be screen reader accessible on some key flows that need it.

  • Adds inputType prop on <FormGroup> that is set to a string of 'radio' or 'checkbox'. If inputType == 'radio' or 'checkbox', the <FormGroup> is rendered as a <fieldset> otherwise it renders our normal <div>
  • That inputType gets passed down to the <InputLabel> which will determine whether the default <label> is changed to a <legend>.

I tested it out locally on RS and it seems to work okay if given the correct inputType on a given <FormGroup>. Also checked after running our tests and there doesn't seem to be a difference / any breaking tests as it relates to getByLabelText ... at least what I saw when label gets switched out for legend (or the tests were not relevant to these changes currently). My thinking is that when the switch does happen (only when we decide to set inputType) and it does happen to break a test, I think we could just change getByLabelText to something like getByRole("group", { name: "Some legend that acts as label for radio or checkbox groups" }));

Example on app/javascript/researcher/surveys/survey_form/survey_question_form_group.jsx when applied:

fieldset.legend.example.mov

Possible iteration? -> Updating RadioButtonGroup and CheckboxButtonGroup to handle the setting legend instead of the FormGroup?

</div>
);

const renderFormGroupChildren = () => (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const renderFormGroupChildren = () => (
const formGroupChildren = (

Since the functional component is executed on every render there's not really a need for this to be inside a function. It could just be assigned to a const. Or if it starts to get more complicated, broken out into a child component

if (isCheckboxOrRadioInputType) {
return renderFieldset();
}
return renderDiv();
Copy link
Collaborator

@rroppolo rroppolo May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though we might have this in the react style guide but I can't find it :( I think maybe it was just raised as a proposal but not officially adopted yet by the team. But the proposal was the use of renderFoo functions inside a component be deprecated in favor of splitting things out into child components to break up a large render method. But wondering here if we can remove some of the duplication anyway through with something like

   return createElement(
     elementType,
      {
        className: classNames(
          'FormGroup',
          props.className, {
            'FormGroup--is-invalid': hasErrors,
            'FormGroup--bordered': props.bordered,
            'FormGroup--inline': props.inline,
          },
        ),
        id: props.id
      },
      formGroupChildren,
    )

We do this in some other places like Card where we take in an elementType prop to make the root element type dynamic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree w/ this proposal (and it could be used in InputLabel as well though I do wonder if that would do better w/ a Boolean (or maybe we make an InputLabel / InputLegend which we use well here.

@@ -6,6 +6,8 @@ import InputLabel from 'src/InputLabel';

import 'scss/forms/form_group.scss';

const FORM_GROUP_INPUT_TYPES = ['input', 'radio', 'checkbox'];
Copy link
Collaborator

@rroppolo rroppolo May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little worried there may be a lot of other input types not represented here, like selects or datepickers. Wondering if we would want to make this prop a boolean and more indicative that it is controlling the fieldset? Like elementType="fieldset"? We could always make a RadioFormGroup component that acts as a wrapper that passes the correct elementType through to FormGroup like

const RadioFormGroup = (props) => (
  <FormGroup 
    elementType="fieldset"
    inputElementType="legend"
    {...props} 
  />
);

if we wanted something a bit more semantic that is still easy to selectively roll out. Then the consumer just needs to switch FormGroup to RadioFormGroup/CheckboxFormGroup and everything else stays the same? Assuming we set a defaultValue for those two props to the non-fieldset case (ie. divs)

@@ -0,0 +1,5 @@
legend {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to scope this to the specific element we're working on or is this something that should be in a generic style override?

As this is written now -- it will apply to every legend in the app, which may not be correct.

if (isCheckboxOrRadioInputType) {
return renderFieldset();
}
return renderDiv();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree w/ this proposal (and it could be used in InputLabel as well though I do wonder if that would do better w/ a Boolean (or maybe we make an InputLabel / InputLegend which we use well here.

@jasonbasuil jasonbasuil requested review from rroppolo and rsaris May 31, 2022 18:48
Copy link
Collaborator

@rroppolo rroppolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for making that change! 💯 🌮 🙌

@jasonbasuil jasonbasuil merged commit bceb3f0 into develop Jun 1, 2022
@jasonbasuil jasonbasuil deleted the feature/UIDS-631-update-input-label-to-support-legend branch June 1, 2022 19:25
jasonbasuil pushed a commit that referenced this pull request Jun 1, 2022
* update FormGroup and InputLabel to support fieldset and legend (#632)
jasonbasuil added a commit that referenced this pull request Jul 14, 2022
* allows Tooltip to open on hover (#487)

* Prepare hotfix 1.24.1 (#492)

* Merge release/1.25.0 into main branch (#494)

* HOTFIX update tooltip primary variant to ux-emerald (#415)

* Feature RS-8352 Tabs (#477)

Add Tabs and Tabs with react-bootstrap and styled-components

* feature/UIDS-442 add Button to DS (#450)

Adds react-bootstrap and Button component to the Design System

* Bug/UIDS-484 Set node version on nightly visual tests (#485)

* chore/UIDS-476 documentation updates (#486)

* Chore/ Add Percy snapshots for buttons (#488)

* Chore/ Delete old sample file for cypress tests (#482)

* Merge hotfix/1.24.1 into develop branch (#493)

* allows Tooltip to open on hover (#487)

* Prepare release 1.25.0

Co-authored-by: Rachel Roppolo <rachel@userinterviews.com>
Co-authored-by: Jane Sebastian <jane@userinterviews.com>
Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: brianCollinsUI <84730553+brianCollinsUI@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* update relative bootstrap imports (#497)

* Prepare hotfix 1.25.1 (#498)

* Merge release/1.26.0 into main branch (#513)

* HOTFIX update tooltip primary variant to ux-emerald (#415)

* Feature RS-8352 Tabs (#477)

Add Tabs and Tabs with react-bootstrap and styled-components

* feature/UIDS-442 add Button to DS (#450)

Adds react-bootstrap and Button component to the Design System

* Bug/UIDS-484 Set node version on nightly visual tests (#485)

* chore/UIDS-476 documentation updates (#486)

* Chore/ Add Percy snapshots for buttons (#488)

* Chore/ Delete old sample file for cypress tests (#482)

* Merge hotfix/1.24.1 into develop branch (#493)

* allows Tooltip to open on hover (#487)

* Merge release/1.25.0 into develop branch (#495)

* allows Tooltip to open on hover (#487)

* Prepare hotfix 1.24.1 (#492)

* Prepare release 1.25.0

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Merge hotfix/1.25.1 into develop branch (#499)

* allows Tooltip to open on hover (#487)

* Prepare hotfix 1.24.1 (#492)

* Merge release/1.25.0 into main branch (#494)

* HOTFIX update tooltip primary variant to ux-emerald (#415)

* Feature RS-8352 Tabs (#477)

Add Tabs and Tabs with react-bootstrap and styled-components

* feature/UIDS-442 add Button to DS (#450)

Adds react-bootstrap and Button component to the Design System

* Bug/UIDS-484 Set node version on nightly visual tests (#485)

* chore/UIDS-476 documentation updates (#486)

* Chore/ Add Percy snapshots for buttons (#488)

* Chore/ Delete old sample file for cypress tests (#482)

* Merge hotfix/1.24.1 into develop branch (#493)

* allows Tooltip to open on hover (#487)

* Prepare release 1.25.0

Co-authored-by: Rachel Roppolo <rachel@userinterviews.com>
Co-authored-by: Jane Sebastian <jane@userinterviews.com>
Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: brianCollinsUI <84730553+brianCollinsUI@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* update relative bootstrap imports (#497)

* Prepare hotfix 1.25.1

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Rachel Roppolo <rachel@userinterviews.com>
Co-authored-by: Jane Sebastian <jane@userinterviews.com>
Co-authored-by: brianCollinsUI <84730553+brianCollinsUI@users.noreply.github.com>

* Chore/wait a bit longer for things to render on some percy snapshots (#503)

* UIDS-438 Add AsyncCreatableSelect (#500)

* UIDS-506 Update Form to handle GET method (#507)

Previously passing a GET method would have worked for Rails, but it wouldn't
put the params in the URL which is the expected behavior. This makes it so we
properly pass GET directly to the form method parameter.

One other thing this does is remove the CSRF params if GET is passed. These are
ignored in GET and thus aren't necessary and would add extra params to the URL.

One potential upgrade that was left on the cutting room floor was passing any
extra props directly to the form component.

* CHORE Fix node version in deploy action (#510)

* CHORE Fix yaml spacing on deploy action (#512)

* feature/UIDS-312 add Dropdown to DS (#502)

* adds Dropdown and subcomponents

* adds DropdownIconToggle

* creates shared button mixins

* remove children proptype, consolidate shared proptypes

* add Percy snapshots for Dropdowns

* Prepare release 1.26.0

Co-authored-by: Rachel Roppolo <rachel@userinterviews.com>
Co-authored-by: Jane Sebastian <jane@userinterviews.com>
Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: brianCollinsUI <84730553+brianCollinsUI@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Bob Saris <bob@userinterviews.com>

* Merge release/1.26.1 into main branch (#517)

* UIDS-501 Export color variables for use in js (#504)

* use font-type-30 on form-control (#516)

* Prepare release 1.26.1

* Fix merge conflicts on 1.27.0

* Merge release/1.28.0 into main branch (#563)

* updates Dropdown documentation, adds Figma addon for illustrations (#554)

* add transparent Button variant & update DropdownIconToggle (#560)

Adding the transparent and outline transparent variant to the Button component. Uses transparent button variant in ModalFooter actions for closing. Updates DropdownToggle to support icon-only dropdown. Removes DropdownIconToggle in favor of using DropdownToggle to better support flexible styling.

* Prepare release 1.28.0

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Merge release/1.29.0 into main branch (#569)

* add CardList to DS (#567)

Adds a CardList layout component to wrap around existing design system Cards.

* update Pill color and border (#568)

Updates Pills colors, removes Pill border, and introduces a Pills layout component to wrap around a collection of Pill components.

* Prepare release 1.29.0

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Merge release/1.29.1 into main branch (#578)

* remove margin from Card (#572)

* rename CardList to CardContainer (#574)

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Merge release/1.29.2 into main branch (#594)

* Button and Link distinction documentation (#587)

* add brand variants to Button (#593)

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* remove extra version in package.json

* Merge release/1.30.0 into main branch (#611)

* removing TrackedButton from export (#603)

* add aria-live to Toast (#605)

* handle setting title prop on Toast (#607)

* update focus state to Button and Select (#601)

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Merge release/1.30.1 into main branch (#618)

* fix styles on Select to allow for tabbing and proper focus (#617)

* Merge release/1.30.2 into main branch (#624)

* allow setting id on InputLabel (#621)

* add id to FormGroup__invalid-feedback (#623)

* Merge release/1.30.3 into main branch (#629)

* update Input focus boder to ux-blue-500 for 3:1 contrast ratio (#628)

* Merge release/1.31.0 into main branch (#633)

* update FormGroup and InputLabel to support fieldset and legend (#632)

* Merge release/1.31.1 into main branch (#642)

* change FormControlLabel label and children to span (#638)

* updating input scss variables (#641)

* Prepare release 1.31.1

* Merge release/1.32.0 into main branch (#660)

* remove required id from FormGroup (#645)

* Fix cypress tests (#647)

* Add data-testid to LoadingOverlay (#652)

* add Link variant to Button component (#659)

* upgrade react-select v5 (#658)

* Add Accordion to DS (#656)

* update snapshots

* Prepare release 1.32.1

Co-authored-by: Jason Basuil <basuilj@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Rachel Roppolo <rachel@userinterviews.com>
Co-authored-by: Jane Sebastian <jane@userinterviews.com>
Co-authored-by: brianCollinsUI <84730553+brianCollinsUI@users.noreply.github.com>
Co-authored-by: Bob Saris <bob@userinterviews.com>
Co-authored-by: Rachel Roppolo <rroppolo@Rachels-MacBook-Pro.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update InputLabel to support legend
3 participants