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

Create Label component #824

Closed
seancolsen opened this issue Nov 16, 2021 · 1 comment · Fixed by #904
Closed

Create Label component #824

seancolsen opened this issue Nov 16, 2021 · 1 comment · Fixed by #904
Labels
ready Ready for implementation type: enhancement New feature or request work: frontend Related to frontend code in the mathesar_ui directory

Comments

@seancolsen
Copy link
Contributor

Problem

We don't have a great way to associate form labels with our input components.

Nesting them like this

<label>
  <span>Foo</span>
  <Select options={choices} bind:value={foo} />
</label>

will work but the svelte a11y linter complains.

Also W3C says:

Generally, explicit labels are better supported by assistive technology.

Proposed solution

  • Create a utility function

    getAppWideUniqueId();

    It will return a string containing an auto-incrementing intger each time the function is called.

    Then we can use that function within components to generate unique id values to use for form inputs.

  • Create a Label component

    • If it recieves a for prop, it uses that on the DOM element.

      Otherwise, it uses a value from getAppWideUniqueId() and also passes that value down through context using a key of 'formInputId' so that nested form input components can read that context value.

  • Modify input components to work with the Label component.

    • If they find a 'formInputId' context value they should use that for their id, (unles passed an id through props).
@seancolsen seancolsen added type: enhancement New feature or request work: frontend Related to frontend code in the mathesar_ui directory ready Ready for implementation labels Nov 16, 2021
@seancolsen
Copy link
Contributor Author

I've marked this as ready since @pavish and I discussed the design over private chat. Pavish, feel free to weigh in with additional clarifications or further ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Ready for implementation type: enhancement New feature or request work: frontend Related to frontend code in the mathesar_ui directory
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

1 participant