Problem/Motivation

In the bootstrap_barrio.theme file select and textarea are excluded from floating labels.

if (theme_get_setting('bootstrap_barrio_float_label') &&
        $variables['element']['#type'] != 'radio' &&
        $variables['element']['#type'] != 'checkbox' &&
        $variables['element']['#type'] != 'date' &&
        $variables['element']['#type'] != 'time' &&
        $variables['element']['#type'] != 'search' &&
        $variables['element']['#type'] != 'select' &&
        $variables['element']['#type'] != 'textarea' &&
        $variables['element']['#type'] != 'managed_file') {
    $variables['float_label'] = theme_get_setting('bootstrap_barrio_float_label');
    $variables['label_display'] = 'after';
  }

Is there a reason for this?
Because select and textarea are supported by Bootstrap and I'd like to keep the styling of my form elements consistent: https://getbootstrap.com/docs/5.3/forms/floating-labels/#textareas

I can't see those excludes in the original commits where support for floating labels was added. (See related issues)

Proposed resolution

Remove the 2 lines that exclude select and textarea from floating lables.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Guido_S created an issue. See original summary.

tguerineau’s picture

Status: Active » Needs review
StatusFileSize
new27.03 KB
new26.85 KB

Hello,

I've been working on addressing this issue and have created a MR with the necessary adjustments. Here's an overview of the changes:

1- Removed Exclusions: In the bootstrap_barrio.theme file, I've removed the lines that excluded select and textarea from floating labels support.

2- Textarea Adjustments:
- Twig template updated: I modified the textarea twig template to adjust its height based on Bootstrap's recommendation. This will ensure a more consistent and visually appealing form design.
- Height Consistency: I've updated the textarea twig template to include a height of 150px. This ensures that textareas maintain a consistent height irrespective of whether the floating label feature is activated or not.
- Hook Preprocess for Textarea: I introduced a hook_preprocess_textarea in the theme file. This hook checks if the 'float_label' theme setting is enabled and accordingly sets a placeholder for the textarea. This placeholder is essentially the title of the textarea, making it intuitive for end-users.

3 - Floating Labels for Select Inputs: Following the Bootstrap documentation, the <label> for .form-selects is always displayed in its floated state. This caters to Bootstrap's specifications and ensures a unified design approach.

Please review the changes and let me know if there are further adjustments needed.

mgstables’s picture

Have tested it on the contact form and the variable "float_label" is not addressed in "textarea.html.twig". So the style (150px) is not applied and the "text-wrapper" remains.

So for now I put the "textarea.html.twig" in my subtheme and adjusted it so it works.

hatuhay made their first commit to this issue’s fork.

hatuhay’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.