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

Fix floating label text cut off in select elements #39483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

theodorejb
Copy link

@theodorejb theodorejb commented Dec 11, 2023

Description

Tweaks line height and padding so that letters with descenders will not be cut off when using a floating label on a <select> element.

Motivation & Context

In Bootstrap 5.3.3 floating labels cause the bottom of some letters like j, g, p, and y to be cut off. This occurs with normal form-select dropdowns in Firefox and Chrome/Edge, and the problem gets significantly worse when using form-select-lg, such that this class is unusable with floating labels in all browsers (including Safari).

Type of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • My change introduces changes to the documentation

Live previews

Related issues

Fixes #33711, fixes #34147

@theodorejb theodorejb requested a review from a team as a code owner December 11, 2023 22:33
@theodorejb theodorejb force-pushed the fix-floating-select-label branch from 9f1c655 to 92122f1 Compare December 11, 2023 22:39
@mdo
Copy link
Member

mdo commented Jan 9, 2024

Unfortunately I think these are somewhat arbitrary values that make our components a little more cumbersome to tweak. I'd rather see us go the route of an improved, balanced vertical padding for both top and bottom vs separate values for both.

@theodorejb
Copy link
Author

theodorejb commented Jan 9, 2024

@mdo Do you mean using the same top/bottom padding for both selects and inputs? I tried that first, and while the new values do work fine for input elements, they do not work for textareas (it causes the label to overlap the textarea contents).

@theodorejb theodorejb force-pushed the fix-floating-select-label branch 4 times, most recently from 078a1c8 to 6e3eda4 Compare January 30, 2024 19:48
@theodorejb
Copy link
Author

theodorejb commented Jan 30, 2024

I changed the approach to use consistent padding for input and select elements, and only override it for textareas.

Note that the increase to line height is necessary to fix the floating label text cutoff issue for select dropdowns. For textareas it also makes the line height more similar to the default line height of 1.5 on textareas without floating labels.

@theodorejb theodorejb force-pushed the fix-floating-select-label branch from 42efade to 232b4a5 Compare March 18, 2024 20:44
@theodorejb
Copy link
Author

I rebased this on top of #39720 since that was approved. I hope this can also make it into a bugfix release.

@theodorejb theodorejb force-pushed the fix-floating-select-label branch from 232b4a5 to 51f1515 Compare June 14, 2024 16:06
@theodorejb theodorejb force-pushed the fix-floating-select-label branch from 51f1515 to e750cad Compare July 18, 2024 15:53
@theodorejb theodorejb force-pushed the fix-floating-select-label branch from e750cad to 8ecf026 Compare August 14, 2024 13:39
@theodorejb
Copy link
Author

Is there any chance this can be reviewed/merged? It fixes an important issue for select inputs with floating labels.

Copy link
Member

@louismaximepiton louismaximepiton left a comment

Choose a reason for hiding this comment

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

I've been trying some other ideas that came to my mind but I couldn't find any better way to do it. I'm fine adding the Sass variables, I'm a bit more worried about the CSS variables that increase the size of the bundle.

Maybe we could calculate the paddings using the existing variables but I'm not sure it would be very handy as well.

Just a quick correction on the line-height to keep the correction very specific.

scss/_variables.scss Show resolved Hide resolved
scss/forms/_floating-labels.scss Outdated Show resolved Hide resolved
Copy link
Member

@louismaximepiton louismaximepiton left a comment

Choose a reason for hiding this comment

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

Fine with the actual on my side since it's better than it was. Still not a big fan of the line-height tweak since it introduces a default scroll for textareas but can't think of another way for now.

@theodorejb theodorejb force-pushed the fix-floating-select-label branch from e6d4be0 to 9ba7f45 Compare November 15, 2024 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Ready to merge
Development

Successfully merging this pull request may close these issues.

Floating labels select option text not fully visible BS5 - Floating Labels + Select - Text is cut off
4 participants