bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Change floating label background-color to transparent

Open Nickiam7 opened this issue 2 years ago • 8 comments

Description

Floating labels have a background-color set to $input-bg. This can look odd if an input uses a browsers native autocomplete which adds a light blue background to the input. Additionally, if a sites design requires styling of input background colors the floating label will appear with the $input-bg color on top of the input background color.

Motivation & Context

Removes the need to manually override the floating label background color.

Type of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [x] Refactoring (non-breaking change)
  • [ ] Breaking change (fix or feature that would change existing functionality)

Checklist

  • [x] I have read the contributing guidelines
  • [x] My code follows the code style of the project (using npm run lint)
  • [ ] My change introduces changes to the documentation
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] All new and existing tests passed

Live previews

Nickiam7 avatar Dec 09 '23 22:12 Nickiam7

  • Before/after demo: https://stackblitz.com/edit/bs-floating-label-bg?file=index.html
  • Light theme screenshot: Floating label bg light
  • Dark theme screenshot: Floating label bg dark

theodorejb avatar Dec 12 '23 04:12 theodorejb

@theodorejb thanks for adding screenshots!

Nickiam7 avatar Dec 12 '23 15:12 Nickiam7

The background color was added to ensure labels were legible on multi-line inputs or textareas.

mdo avatar Dec 12 '23 22:12 mdo

@mdo Is there an example where it improves legibility? It seems like the label background is only visible when an input is autofilled.

theodorejb avatar Dec 19 '23 16:12 theodorejb

Here's an example where a solid background is useful: Screenshot 2023-12-19 at 18 29 48

With the fix in this PR:

Screenshot 2023-12-19 at 18 31 14

julien-deramond avatar Dec 19 '23 17:12 julien-deramond

@julien-deramond Ah, that is useful for when textarea contents are scrolled.

theodorejb avatar Dec 19 '23 18:12 theodorejb

Thanks for the context @mdo and thanks for the screenshots @julien-deramond! It does make sense for textareas, I def agree.

Does it makes sense to apply this fix to an input field of type password and email since those will almost always be single line inputs? Or I could just make a note how to adjust the css to fix this in the docs.

Nickiam7 avatar Dec 22 '23 00:12 Nickiam7

Does it makes sense to apply this fix to an input field of type password and email since those will almost always be single line inputs? Or I could just make a note how to adjust the css to fix this in the docs.

I don't think there was any particular reason we didn't special case this based on the HTML element. I'm down to see if we can scope the addition of the background-color to just the textarea. Want to take a crack?

mdo avatar Jan 09 '24 02:01 mdo

I think this can be closed since #39720 was merged.

theodorejb avatar Jul 10 '24 13:07 theodorejb

I think this can be closed since #39720 was merged.

Yes you're right, thanks for pointing this out @theodorejb Thanks to all in this PR for the work 🙏, it has been handled slightly differently in https://github.com/twbs/bootstrap/pull/39720

julien-deramond avatar Jul 10 '24 14:07 julien-deramond