Skip to content

feat: built-in 'underline' for form control #27239

Description

@Wasenshi123

Prerequisites

Describe the Feature Request

According to this issue : #27236

I am trying to achieve the original look and behavior with new modern syntax about label and AT.

https://stackblitz.com/edit/3we1ad-kzmne4?file=index.html

As you can see, the underline in original is resembling the underline in real paper form for user to fill in the blank.

(But what I tried to do result in the whole thing got underlined, including the label)

It would be nice to have built-in support functionality about this. for each form control (ion-input, ion-select, ion-textarea)

Describe the Use Case

I am trying to achieve the original look and behavior with new modern syntax about label and AT.

https://stackblitz.com/edit/3we1ad-kzmne4?file=index.html

Describe Preferred Solution

No response

Describe Alternatives

No response

Related Code

https://stackblitz.com/edit/3we1ad-kzmne4?file=index.html

Additional Information

As I mentioned, it should be customizable, especially the length (where you want it to underline, the whole, or exclude label and just the fill in area).

Activity

  1. sean-perkins commented on Apr 19, 2023

    @sean-perkins
    Contributor

    Hello @Wasenshi123 thanks for this feature request.

    Can you perhaps take a screenshot from your example of which behavior you are referring to for the underline form control?

    In your original desired UI you are using floating labels, but in the modern syntax you are using fixed labels instead. I forked your example to make them consistent: https://stackblitz.com/edit/3we1ad-a1b8sd?file=index.html

    Outside of the small visual adjustments between legacy and modern to align with the Material design spec, I don't currently see an issue with the underline between the displays.

  2. added
    needs: reply
    on Apr 19, 2023
  3. Wasenshi123 commented on Apr 20, 2023

    @Wasenshi123
    Author

    Hello @Wasenshi123 thanks for this feature request.

    Can you perhaps take a screenshot from your example of which behavior you are referring to for the underline form control?

    In your original desired UI you are using floating labels, but in the modern syntax you are using fixed labels instead. I forked your example to make them consistent: https://stackblitz.com/edit/3we1ad-a1b8sd?file=index.html

    Outside of the small visual adjustments between legacy and modern to align with the Material design spec, I don't currently see an issue with the underline between the displays.

    I mean to have the ability to set this on the form control

    image

    As I demonstrated, I tried to add it manually with css on the new syntax one, but that's not quite the exact feeling because it underline the whole thing. So I think the built-in feature for this would be nice.

  4. added and removed
    needs: reply
    on Apr 20, 2023
  5. Wasenshi123 commented on Apr 20, 2023

    @Wasenshi123
    Author

    @sean-perkins I see now what is your point.

    Please see this screen shot, my desired structure has the behavior to change label placement based on screen size. So at wider screen, the difference is noticeable:

    image

    My example is also updated to dynamically change label placement now.

  6. sean-perkins commented on Apr 21, 2023

    @sean-perkins
    Contributor

    Thank you for the extra detail + screenshots! I understand the differences now 👍

    The underline border always being visible could be accomplished if Ionic exposed shadow parts for the native wrapper on each control (or CSS variables for border, since not all controls use shadow dom).

    The underline width is a much larger task.

    For ion-input, the input highlight would need to be conditionally rendered either at the host level (to fill the entire width) or within the .native-wrapper when only wanting to display the highlight under the control. The .native-wrapper would also need: position: relative to contain the element positioning.

    Here is an example concept with manually modifying the DOM and adjusting styling:

    Kapture.2023-04-21.at.14.12.17.mp4

    ion-select isn't as straight forward. The control does not fill the entire container space. I need to do additional investigation on our decision behind these styles, as I don't see the same thing against: https://material-components.github.io/material-components-web-catalog/#/component/select.

    A mock API could look like:

    <ion-input label="Name" label-placement="fixed" highlight="control"></ion-input>

    It would support two options full and control, defaulting to full.

    I'll discuss with the team and see if there are alternatives that I may be missing or any questions around the feature's feasibility.

  7. sean-perkins commented on Apr 24, 2023

    @sean-perkins
    Contributor

    Thinking through the border aspect specifically, we could do something similar to:

    /* user land styles - border is always visible */
    ion-input {
      --border-width: 1px;
    }

    The helper/error text styling could be refactored to something similar to this, when active:

    /* input.scss */
    :host(.has-helper-text), :host(.has-error-text) {
     --border-width: 1px;
    }

    Lastly, the .input-wrapper styles could be refactored to make use of the border styles, applying the border on the bottom instead of the helper/error text applying a border top:

    /* input.scss */
    .input-wrapper {
      border-bottom: var(--border-width) var(--border-style) var(--border-color);
    }

    This would allow the default implementation to apply the border style/color when the helper/error text is used, but developers could optionally override and apply the border at any time through the --border-width, --border-style and --border-color CSS variables.

    I am going to move this request into a labeled feature request.

  8. added
    type: feature request
    package: core
    on Apr 24, 2023
  9. Majstr commented on May 13, 2024

    @Majstr

    I am keep coming to this issue but it is not solving my problem. Since Ionic v7 you removed slot="error" which was option to display error in input. Now you put errorText which looks good at first glance. But when you go deeper you can see that it completely breaks existing logic. So there is no way to use this with list because it makes double line. So all the documentation is, put inputs in a list. But now with this new errorText official statement is don't use it in a list. And explanation is:

    If you need to provide more context on a input, consider using an ion-note underneath the ion-list.

    So I would have 10 inputs in a list and then at the en of the list I will put wall of text for each input what is wrong with entered data? Or I should make a list for each input separately? It totally breaks validation messages for inputs in a list. Or I am missing something essential.

    On top of it all select doesn't even have errorText or helperText. All my forms are broken, probably only solution is to go back to v6. And in v8 nothing was done about this topic.

  10. howlettga commented on Aug 15, 2024

    @howlettga

    Is there any intention to support this? Right now the documentation shows most inputs inside an ion-item element, which breaks the errorText functionality. In my opinion, input validation is a requirement for inputs, so the input has been broken for 2 major releases. The documentation doesn't demonstrate a valid way to add realistic input scenarios.

    The only workaround right now seems to be use lines="none" on all ion-item elements or use ion-input elements without any list. In addition, you have to stub in errorText="void" or some other valid string to all inputs that aren't required just to get matching user interface.

    Is there any plans to get form functionality working or at least document input usage in a way that reflects real world scenarios?

  11. muratcorlu commented on Apr 1, 2026

    @muratcorlu

    This is still a big frustration for developers to handle error messages well in Ionic. Hopefully we'll have a built-in solution to this. But I wanted to just share my workaround anyway.

    I add an ion-note element with "error-message" class next to the ion-list item where I want to show an error message:

    <ion-list inset>
      <ion-item-group>
        <ion-item>
          <ion-input label="Default From Address" placeholder="hello">
            <ion-note slot="end">{{ '@' }}example.com</ion-note>
          </ion-input>
        </ion-item>
      </ion-item-group>
    </ion-list>
    <ion-note color="danger" class="list-note error-message">Please enter a valid email handle</ion-note>
    <ion-note color="medium" class="list-note">This is the default sender address for your emails.</ion-note>

    And in my global.scss file, I defined this style to show error state when an input is changed:

    ion-list + .error-message {
      display: none;
    }
    
    ion-list:has(.ion-invalid.ion-touched) {
      ion-item:has(.ion-invalid.ion-touched) {
        --ion-background-color: var(--ion-color-danger-tint);
        --color: var(--ion-color-danger);
    
        ion-note {
          color: var(--ion-color-danger-shade);
        }
      }
    
      & + .error-message {
        display: block;
      }
    }

    This results something like this in error state:

    Image

    You may need to play with coloring and make some additions if you have different items in your ion-item elements. (I use iOS 26 Theme here by @rdlabo)

  12. rdlabo commented on Aug 28, 2026

    @rdlabo
    Contributor

    I found two separate issues related to supporting text inside ion-item.

    1. Configuring errorText renders the bottom container even when there is no visible error

    The current condition is based only on whether helperText or errorText is configured:

    const hasHintText = !!helperText || !!errorText;

    As a result, configuring errorText renders the bottom container before the control has both the ion-invalid and ion-touched classes.

    The error text itself is correctly hidden, but the empty bottom container remains. This causes its border or padding to be applied even when there is no visible error.

    The rendering condition should instead reflect the supporting text that is visible in the current validation state:

    const hasHintText = isInvalid ? !!errorText : !!helperText;

    For controls with a counter, the bottom container should continue to render when the counter is enabled:

    const hasHintText = isInvalid ? !!errorText : !!helperText;
    const hasCounter = counter === true && maxlength !== undefined;
    
    if (!hasHintText && !hasCounter) {
      return;
    }

    2. A parent cannot reliably detect whether a Shadow DOM form control is displaying supporting text

    A parent can detect the ion-invalid and ion-touched classes on the host. However, those classes do not indicate whether errorText is configured or whether supporting text is actually being displayed.

    This distinction matters when a third-party theme needs to adjust the surrounding ion-item, for example by removing the item border when the form control displays its own border and supporting text.

    For ion-input and ion-textarea, which use scoped encapsulation, the theme can inspect the rendered content:

    ion-item {
      &:has(ion-input .input-bottom > :is(.helper-text:not(:empty), .error-text:not(:empty))),
      &:has(ion-textarea .textarea-bottom > :is(.helper-text:not(:empty), .error-text:not(:empty))) {
        --inner-border-width: 0;
        --inner-padding-bottom: 4px;
      }
    
      ion-input .input-bottom:not(:has(> :is(.helper-text:not(:empty), .error-text:not(:empty)))),
      ion-textarea .textarea-bottom:not(:has(> :is(.helper-text:not(:empty), .error-text:not(:empty)))) {
        display: none;
      }
    }

    The equivalent approach is not possible for ion-select, ion-checkbox, or ion-toggle because their supporting text is inside Shadow DOM.

    CSS parts allow styling internal elements, but they do not allow inspecting their content or selecting a parent ion-item. Attribute selectors are also unreliable when helperText or errorText is assigned dynamically as a JavaScript property.

    Fixing the first issue would remove the empty bottom container. The remaining requirement is a reliable way for parent elements and third-party themes to determine whether a Shadow DOM form control is currently displaying supporting text.

    If these directions are acceptable, I would be happy to submit a PR with tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coretype: feature request

    Fields

    Stage

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions