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

feat(rangeinput): creates form RangeInput component, test, and stories #194

Merged
merged 5 commits into from
May 26, 2020

Conversation

duncan-truss
Copy link
Contributor

@duncan-truss duncan-truss commented May 21, 2020

Description

This PR adds the USWDS Range component to the available form inputs.

The component renders as an input of type range and an optional Label.

The min, max, step, and value fields are optional and default to:
min: 0
max: 100
step: 1
value: max/2

I copied the ref code from somewhere else but don't know entirely why it's necessary or all of the possible types it could be. I think I remember there is an old deprecated way to do refs from the official tutorial.

Screen Shot 2020-05-21 at 6 09 42 PM

Open Questions

  • Should the label be excluded all together from the component or passed whole instead of built out of label and hint attributes?
  • The USWDS guidance recommends that you label the min and max ends, should we offer that functionality?
  • Should the component accept any event listeners?
  • I added the list prop to support linking to a datalist element. This has next to no browser visual support (ticks in chrome if the usa-range class isn't applied) at the moment.
  • Similar to the start and end labels should there be an <output> field that displays the slider value or would that be handled externally by something that uses an event listener?
  • Firefox accepts an orient="vertical" attribute but everyone else just uses CSS so I omitted it

MDN input range element documentation

#81

@duncan-truss duncan-truss self-assigned this May 21, 2020
@duncan-truss duncan-truss linked an issue May 21, 2020 that may be closed by this pull request
Copy link
Contributor

@eamahanna eamahanna left a comment

Choose a reason for hiding this comment

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

Looks good :)

@eamahanna
Copy link
Contributor

Here are my thoughts on the questions you listed in your description:

Should the label be excluded all together from the component or passed whole instead of built out of label and hint attributes?

  • I think it is fine including the label or not. The text input component does not include a label however.

The USWDS guidance recommends that you label the min and max ends, should we offer that functionality?

  • I think there should at least be a story showing this. I am unsure if the component should contain them because I don't know how they are suppose to be styled. Maybe there is guidance on that.

Should the component accept any event listeners?

  • I don't think you need to include a listener explicitly. There is on onChange prop defined in the React.InputHTMLElement interface
 interface InputHTMLAttributes<T> extends HTMLAttributes<T> {
        accept?: string;
        alt?: string;
        autoComplete?: string;
        autoFocus?: boolean;
        capture?: boolean | string; // https://www.w3.org/TR/html-media-capture/#the-capture-attribute
        checked?: boolean;
        crossOrigin?: string;
        disabled?: boolean;
        form?: string;
        formAction?: string;
        formEncType?: string;
        formMethod?: string;
        formNoValidate?: boolean;
        formTarget?: string;
        height?: number | string;
        list?: string;
        max?: number | string;
        maxLength?: number;
        min?: number | string;
        minLength?: number;
        multiple?: boolean;
        name?: string;
        pattern?: string;
        placeholder?: string;
        readOnly?: boolean;
        required?: boolean;
        size?: number;
        src?: string;
        step?: number | string;
        type?: string;
        value?: string | string[] | number;
        width?: number | string;

        onChange?: ChangeEventHandler<T>;   }

I added the list prop to support linking to a datalist element. This has next to no browser visual support (ticks in chrome if the usa-range class isn't applied) at the moment.

  • Given that it is optional and defined in the InputHTMLAttributes, I don't think it needs to be an explicit prop, but you can show it in a story maybe?

Similar to the start and end labels should there be an field or would that be handled externally by something that uses an event listener?

  • I think this is the inputHTMLAttribute onChange prop

@duncan-truss
Copy link
Contributor Author

Here are my thoughts on the questions you listed in your description:

Should the label be excluded all together from the component or passed whole instead of built out of label and hint attributes?

* I think it is fine including the label or not. The text input component does not include a label however.

The USWDS guidance recommends that you label the min and max ends, should we offer that functionality?

* I think there should at least be a story showing this. I am unsure if the component should contain them because I don't know how they are suppose to be styled. Maybe there is guidance on that.

Should the component accept any event listeners?

* I don't think you need to include a listener explicitly. There is on onChange prop defined in the React.InputHTMLElement interface
 interface InputHTMLAttributes<T> extends HTMLAttributes<T> {
        accept?: string;
        alt?: string;
        autoComplete?: string;
        autoFocus?: boolean;
        capture?: boolean | string; // https://www.w3.org/TR/html-media-capture/#the-capture-attribute
        checked?: boolean;
        crossOrigin?: string;
        disabled?: boolean;
        form?: string;
        formAction?: string;
        formEncType?: string;
        formMethod?: string;
        formNoValidate?: boolean;
        formTarget?: string;
        height?: number | string;
        list?: string;
        max?: number | string;
        maxLength?: number;
        min?: number | string;
        minLength?: number;
        multiple?: boolean;
        name?: string;
        pattern?: string;
        placeholder?: string;
        readOnly?: boolean;
        required?: boolean;
        size?: number;
        src?: string;
        step?: number | string;
        type?: string;
        value?: string | string[] | number;
        width?: number | string;

        onChange?: ChangeEventHandler<T>;   }

I added the list prop to support linking to a datalist element. This has next to no browser visual support (ticks in chrome if the usa-range class isn't applied) at the moment.

* Given that it is optional and defined in the InputHTMLAttributes, I don't think it needs to be an explicit prop, but you can show it in a story maybe?

Similar to the start and end labels should there be an field or would that be handled externally by something that uses an event listener?

* I think this is the inputHTMLAttribute onChange prop

Thank you for these answers!

Since the InputHTMLAttributes contain min, max, and step should I remove them from the RangeInputProps interface along with list?

@haworku
Copy link
Contributor

haworku commented May 22, 2020

@duncan-truss to answer your questions about the type interface: yes - remove them from there. We don't need to retype them.

Copy link
Contributor

@suzubara suzubara left a comment

Choose a reason for hiding this comment

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

looking good! My only blocking comment is about removing the label.

// Range defaults to min = 0, max = 100, step = 1, and value = (max/2) if not specified.
const {
id = 'range-slider',
name = 'range',
Copy link
Contributor

Choose a reason for hiding this comment

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

this is my 🔥 opinion and is more of a general comment about form inputs, but IMO id and name are so fundamental to building HTML forms that I don't think we need to provide default values, and I also think they should be required in the prop type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's great context, keep the opinions coming I don't have any of my own yet.


return (
<>
{label && (
Copy link
Contributor

Choose a reason for hiding this comment

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

To answer your question, the label should not be included in the component (following the examples of the other input components, which only render an <input> element). It should be up to the user to add labels.

max={max}
step={step}
list={list}
{...inputProps}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: any of these props that aren't handled specifically in our code (ie, className) can be passed in as part of ...inputProps instead of having to be destructured & passed in explicitly.

@suzubara
Copy link
Contributor

I copied the ref code from somewhere else but don't know entirely why it's necessary or all of the possible types it could be. I think I remember there is an old deprecated way to do refs from the official tutorial.

This inputRef prop is one that each input should accept, and allows an implementation to have direct access to the input DOM element which is often required for things like form library integration, or managing focus on form elements.

  • The USWDS guidance recommends that you label the min and max ends, should we offer that functionality?

Since USWDS doesn't provide any examples or styles I think we can leave it for now

@haworku
Copy link
Contributor

haworku commented May 22, 2020

This inputRef prop is one that each input should accept, and allows an implementation to have direct access to the input DOM element which is often required for things like form library integration, or managing focus on form elements.

Ah, makes sense @suzubara that's great context - I wasn't sure either about this tbh (the use case specifically). This is an example of something we can include in #73 .

Regarding the types, just generally I wonder if something like inputRef should be a shared type in the /forms folder. Maybe we just define it in TextInput for now and export it for use?

@trussworks-infra-zz
Copy link

trussworks-infra-zz commented May 22, 2020

Warnings
⚠️

Changes were made to package.json, but not to yarn.lock - Perhaps you need to run yarn install?

Generated by 🚫 dangerJS against 56bb01e

Copy link
Contributor

@suzubara suzubara left a comment

Choose a reason for hiding this comment

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

there's just some minor cleanup but nothing blocking. looks good!

</>
)

const labelHint = <>(Some hint)</>
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like there are a few unused variables now that can be deleted. FWIW I think it would be fine to include a story that renders the RangeInput alongside a Label if you wanted to demo that.

import React from 'react'
import classnames from 'classnames'

import { Label } from '../Label/Label'
Copy link
Contributor

Choose a reason for hiding this comment

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

this import can be deleted

@duncan-truss duncan-truss merged commit 8e0179f into develop May 26, 2020
@duncan-truss duncan-truss deleted the ds-range-slider-component-81 branch May 26, 2020 16:33
suzubara pushed a commit that referenced this pull request May 28, 2020
* Bump standard-version from 7.1.0 to 8.0.0

Bumps [standard-version](https://github.com/conventional-changelog/standard-version) from 7.1.0 to 8.0.0.
- [Release notes](https://github.com/conventional-changelog/standard-version/releases)
- [Changelog](https://github.com/conventional-changelog/standard-version/blob/master/CHANGELOG.md)
- [Commits](conventional-changelog/standard-version@v7.1.0...v8.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Created issue templates

Created issue templates for feature request & bug report, with default labels.

* fix: removes the usa-search class name from the form component (#184)

fix #163

* fix: accept id and name props for Search component input field (#183)

* fix: accept id and name props for Search component input field
* fix: qualify id and name props for input field to not clash with form
fix #162

* feat: add dateInput component for forms (#144)

* Added dateInput component and dateInputGroup component for forms

* fix: extends header menu to accept list props for corresponding id (#188)

fix #165

* fix: update gov banner to uswds version 2.7.0

* chore: upgrade uswds to 2.7.0

* docs: add documentation for Trussels (#190)

* docs: add documentation for Trussels

* docs: clean up readme to meet project standards

* docs: add to active maintainers

* docs: add first pass of security policy

Co-authored-by: HANA <hana@truss.works>

* feat: add Footer component #142 (#146)

- adds slim, medium, and big footers with mobile styles
- adds new components, specifically Address, Footer,  FooterNav, FooterExtendedNavList, Logo, SocialLinks

* build(deps-dev): bump @testing-library/jest-dom from 5.7.0 to 5.8.0 (#197)

* build(deps-dev): bump typescript from 3.9.2 to 3.9.3 (#196)

* build(deps-dev): bump @storybook/react from 5.3.18 to 5.3.19 (#198)

* build(deps-dev): bump stylelint from 13.4.1 to 13.5.0 (#199)

* build(deps-dev): bump lint-staged from 10.2.4 to 10.2.6 (#200)

* build(deps-dev): bump @storybook/addon-info from 5.3.18 to 5.3.19 (#201)

* feat(rangeinput): creates form RangeInput component, test, and stories (#194)

* feat(rangeinput): creates form RangeInput component, test, and stories

* feat: add RangeInput component to index.ts for entrypoint export

* feat: remove overalpping interface props with HTMLInputAttributes type

* feat: require id and name props, remove label, remove redundant unpack

* feat: remove unused label import in component, show label usage in story

fixes #81

* docs: add landing page and documentation page template stories (#195)

* docs: add landing page and documentation page template stories

* docs(storybook): add current class to header navigation

* ci: lint PR titles instead of commits #159 (#210)

* chore: add semantic pr workflow

* chore: update workflow

* Remove commitlint hook

* Clarify PR linting requirement

Co-authored-by: HANA <hana@truss.works>

* chore(release): 1.4.0

* Remove duplicate entry from changelog

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Duncan <52669884+duncan-truss@users.noreply.github.com>
Co-authored-by: Emily Mahanna <56279459+eamahanna@users.noreply.github.com>
Co-authored-by: HANA <hana@truss.works>
@haworku haworku mentioned this pull request Jun 29, 2020
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.

USWDS Component: Range slider
5 participants