ory / elements

Ory Elements is a component library that makes building login, registration and account pages for Ory a breeze. Check out the components library on Chromatic https://www.chromatic.com/library?appId=63b58e306cfd32348fa48d50
https://ory.sh
Apache License 2.0
85 stars 44 forks source link

feat: associate all inputs with labels via unique IDs #113

Closed LBBO closed 1 year ago

LBBO commented 1 year ago

Related Issue or Design Document

Originated in SEO improvements for the website, but should benefit everyone :) Having inputs and labels associated with each other improves accessibility, as screen readers know how to announce inputs better. It also improves things for sighted users, as the inputs become focusable / toggleable via a click on the label. Using unique IDs is good for avoiding ID collisions with users' websites and necessary for allowing multiple uses of the same component.

Checklist

Further comments

LBBO commented 1 year ago

Just realized: is changing the nav ID from a constant to something dynamic potentially a breaking change for some people? If so, maybe that particular change should be reverted

Benehiko commented 1 year ago

Just realized: is changing the nav ID from a constant to something dynamic potentially a breaking change for some people? If so, maybe that particular change should be reverted

We use the nav inside AX https://github.com/ory/kratos-selfservice-ui-node but i don't think it should break anything. the tests rely on either the test-id or the url of the link/button. Input fields have names from kratos which are also relied upon.

Benehiko commented 1 year ago

We should actually just need to check if the hook is usable inside AX since it's using the ReactDOMServer.renderToStaticMarkup() function

LBBO commented 1 year ago

Seems to be possible, if the DOM structure is identical on server and client

With server rendering, useId requires an identical component tree on the server and the client. If the trees you render on the server and the client don’t match exactly, the generated IDs won’t match.

https://react.dev/reference/react/useId

Benehiko commented 1 year ago

Have you been able to verify if this works?

LBBO commented 1 year ago

Didn't work before; works now 🎉