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

Remove unnecessary classes and ids from labels #449

Open
stevepiercy opened this issue Aug 22, 2020 · 9 comments
Open

Remove unnecessary classes and ids from labels #449

stevepiercy opened this issue Aug 22, 2020 · 9 comments
Labels
BS5 Bootstrap 4
Milestone

Comments

@stevepiercy
Copy link
Member

<label> in BS4 does not have any classes or ids in its attributes. It has only the for attribute. Remove any default classes and ids.

@stevepiercy stevepiercy added the BS5 Bootstrap 4 label Aug 22, 2020
@stevepiercy stevepiercy added this to the 3.0.0 milestone Aug 22, 2020
@trollfot
Copy link

The question arises for "required". Without it, there's no marker to show a field being required.

@stevepiercy
Copy link
Member Author

What do you think about this solution?

https://stackoverflow.com/a/76871043/2214933

I think less markup is better. But I do not know whether this visual only solution is best for accessibility. I assume by virtue of the required attribute on the input, that screen readers would inform the user.

@stevepiercy
Copy link
Member Author

Answering my own question: https://www.accessibility-developer-guide.com/examples/forms/required/#using-html-5-client-side-validations.

Therefore the CSS visually-only solution is fine.

@trollfot
Copy link

The ":has(+...)" does not work on every browser. It does not, on my firefox but does on my chromium.

@trollfot
Copy link

After fiddling around in the templates, I also fail to see how we'd use a purely CSS solution with composite fields, like the date parts. The label is then linked to several inputs lost in the depths of HTML markings. This is also true for other complex fields that can't just be input:required or select:required

@trollfot
Copy link

maybe a solution would be : https://getbootstrap.com/docs/5.0/forms/floating-labels/#example

@trollfot
Copy link

Then the label is AFTER the field and can be selected without advanced CSS that don't work everywhere

@stevepiercy
Copy link
Member Author

So for example, doing one of these?

<div class="bd-example">
<div class="form-floating mb-3">
  <input type="email" class="form-control" id="floatingInput" placeholder="[email protected]">
  <label for="floatingInput">Email address (required)</label>
</div>
<div class="form-floating">
  <input type="password" class="form-control" id="floatingPassword" placeholder="Password">
  <label for="floatingPassword">Password <span class="text-danger">*</span></label>
</div>
</div>

Screenshot 2023-11-22 at 2 18 37 PM

For the former, translations would be better supported, it would be more accessible, and it would avoid an abstraction of a red * to show that the field is required. We could adapt this approach for radios and checkboxes, too. The downside is that there would be longer text instead of a *. What do you think?

@trollfot
Copy link

If we go the full text way ('required'), then we do not need to change anything in the html structure. The proposed floating labels were meant to allow an easier CSS selector to apply a red asterisk. I, myself, think a visual cue is probably cheaper (we just keep what we currently have with a class='required').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BS5 Bootstrap 4
Projects
None yet
Development

No branches or pull requests

2 participants