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

Accessible form validation #1044

Merged
merged 8 commits into from
Mar 24, 2020
Merged

Conversation

simurai
Copy link
Contributor

@simurai simurai commented Mar 10, 2020

This is on top of #1028. It adds a "success" tooltip when a form input is valid. 👀 Docs preview

image

<form>
  <div class="form-group successed">
    <div class="form-group-header">
      <label for="username-input">Username</label>
    </div>
    <div class="form-group-body">
      <input
        class="form-control"
        type="text"
        value="monalisa"
        id="unsername-input"
        aria-describedby="username-input-validation"
      />
    </div>
    <p class="note success" id="username-input-validation">monalisa is available</p>
  </div>
</form>

The docs example also got split into 3 seperate examples so that the same ids can be used.

Before After
screenshot before screenshot after

Why?

When an input is valid we typically show a checkmark icon. But screen reader users don't get notified. Adding a success message adds confidence that everything is fine. 👌😌

See https://github.com/github/github/issues/132199

Concerns + alternatives

We could consider removing the .success , .error and .warning classes since we already set the state on the .form-group element. Maybe once we start refactoring all the form-groups on dotcom? 🤔 And also get rid of the .form-group-header and .form-group-body that are not really needed.


/cc @primer/ds-core

@vercel
Copy link

vercel bot commented Mar 10, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/primer/primer-css/1923d2idj
✅ Preview: https://primer-css-git-accessible-form-validation.primer.now.sh

@vercel vercel bot temporarily deployed to Preview March 11, 2020 00:22 Inactive
simurai added 2 commits March 11, 2020 09:26
to make it work with <auto-check>
@vercel vercel bot temporarily deployed to Preview March 11, 2020 01:12 Inactive
@vercel vercel bot temporarily deployed to Preview March 11, 2020 01:20 Inactive
To match <auto-check>
@vercel vercel bot temporarily deployed to Preview March 11, 2020 01:42 Inactive
@simurai simurai marked this pull request as ready for review March 11, 2020 01:49
@muan
Copy link
Contributor

muan commented Mar 11, 2020

Persistent error tooltip blocking the next field

Currently the error message would not go away until the error is addressed. I don't suppose the success message should stay? the check mark currently stays.

When an input is valid we typically show a checkmark icon.

Any thoughts around adding this to Primer? This is currently custom CSS in github/github.

@vercel vercel bot temporarily deployed to Preview March 12, 2020 01:20 Inactive
Copy link
Contributor

@emilybrick emilybrick left a comment

Choose a reason for hiding this comment

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

👍 thanks for doing this

@simurai
Copy link
Contributor Author

simurai commented Mar 12, 2020

@muan Currently the error message would not go away until the error is addressed. I don't suppose the success message should stay? the check mark currently stays.

Yes, right. It would need support in <auto-check>. Or when used without <auto-check>, additional custom JS.

Some alternatives I can think of:

  • Change the markup and rely on .form-control:focus + .success to show the tooltip. When the focus moves away, the tooltip would be hidden.
  • Use some CSS animation with a delay to hide the tooltip after a few seconds. Not sure if that would work ok with making it re-appear?
  • Not use a tooltip, but instead show the message underneath. Here an example:
    valid
    The message can stay because it doesn't cover anything. And you can also come back later and get a reminder why it wasn't valid. Downside would be that it pushes content down when it appears and can feel jarring.
  • Browsers offer "native" form validation. But I haven't looked into browser support and might be hard to add custom styling for it.

Any thoughts around adding this to Primer? This is currently custom CSS in github/github.

Looks like the styles already are in Primer CSS. But the icons are still on github/github: #442 + #722. Maybe this suggestion #442 (comment) of using a variable for the path might work?

@muan
Copy link
Contributor

muan commented Mar 12, 2020

Change the markup and rely on .form-control:focus + .success to show the tooltip. When the focus moves away, the tooltip would be hidden.

This seems fine, though I'm not sure if this needs to be a special case for success message?

Not use a tooltip, but instead show the message underneath. ... And you can also come back later and get a reminder why it wasn't valid.

Personally I am a fan of not hiding content, though keep in mind that some fields already have help text below them. Currently they're replaced if there's an error message.

organization creation from shows a help text below the username field

Browsers offer "native" form validation. But I haven't looked into browser support and might be hard to add custom styling for it.

The native validation message isn't reliably read to screen reader, and afaik it's not stylable. For example, firefox shows it as a native tooltip, only when you hover over the form field.

@simurai
Copy link
Contributor Author

simurai commented Mar 16, 2020

This seems fine, though I'm not sure if this needs to be a special case for success message?

Right. If, we should change all types to use the same.

Personally I am a fan of not hiding content, though keep in mind that some fields already have help text below them. Currently they're replaced if there's an error message.

Yeah, maybe it could be something like mini flash alerts that appear under inputs and don't replace these "help texts".

Ok, how about this:

  1. Keep this PR as is.
  2. Add support for success messages to <auto-check>. I can try to make a PR.
  3. Explore a redesign of our form validation.
  4. If we're happy with the redesign, refactor all .form-inputs on dotcom. Maybe use a ViewComponent.

Refactoring .form-inputs on dotcom is needed at some point because we wanna remove all the dls, see #1028.

@muan
Copy link
Contributor

muan commented Mar 16, 2020

  • Keep this PR as is.

Are you thinking about adding the :focus in dotcom instead?

  • Add support for success messages to <auto-check>. I can try to make a PR.

I'll take this since it involves changing or JS behavior and there's quite a lot of tech debt there.

Otherwise sounds good.

@simurai
Copy link
Contributor Author

simurai commented Mar 20, 2020

Are you thinking about adding the :focus in dotcom instead?

Was think the success tooltip should show up as soon as the form is valid. So it matches the announcement to screen readers. I guess adding that in here? And unlike errors, maybe the green tooltip needs to be hidden on blur, once the user moves the focus to another element? So it doesn't keep covering something underneath.

I'll take this since it involves changing or JS behavior and there's quite a lot of tech debt there.

That would be great. 🙇 I can make a new Primer CSS release next week so that the styles will be available on dotcom.

@vercel vercel bot temporarily deployed to Preview March 20, 2020 09:13 Inactive
@simurai simurai changed the base branch from accessible-form-groups to release-14.3.0 March 24, 2020 02:07
@simurai simurai merged commit a15aba0 into release-14.3.0 Mar 24, 2020
@simurai simurai deleted the accessible-form-validation branch March 24, 2020 02:08
@simurai simurai mentioned this pull request Mar 27, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants