Skip to content

feat: custom html label for input and textarea with modern form syntax #27061

Closed

Description

@emeryao

Prerequisites

Describe the Feature Request

Inline html template for label on ion-input

Describe the Use Case

with [email protected] I'm able to add some html and styles the label text like code below

<ion-item>
    <ion-label [position]="'stacked'">SomeField<small><i>Optional</i></small></ion-label>
    <ion-input></ion-input>
</ion-item>

but now with [email protected] the <ion-lable> component is discouraged and the [label] property of ion-input seems accepts strings only
so is there a workaround to get this done like before?

Describe Preferred Solution

No response

Describe Alternatives

No response

Related Code

No response

Additional Information

No response

Activity

  1. changed the title [-]feat: inline html for label property[/-] [+]feat: inline html for label property with [email protected][/+] on Mar 30, 2023
  2. self-assigned this
    on Mar 30, 2023
  3. liamdebeasi commented on Mar 30, 2023

    @liamdebeasi
    Contributor

    Thanks for the report. This feature requires that ion-input and ion-textarea use the Shadow DOM which breaks autofill on iOS 14-16: https://bugs.webkit.org/show_bug.cgi?id=172567 (This feature was recently fixed, but it has not been released yet). As a result, we are unable to add the requested feature at this time.

    However, you can continue using ion-label with aria-labelledby:

    <ion-item>
      <ion-label id="my-label">My Label</ion-label>
      <ion-input aria-labelledby="my-label"></ion-input>
    </ion-item>

    Can you give this a try, and let me know if it works?

  4. added
    needs: reply
    on Mar 30, 2023
  5. removed their assignment
    on Mar 30, 2023
  6. emeryao commented on Mar 31, 2023

    @emeryao
    Author

    Thanks for your response @liamdebeasi
    I tried the code above and it works but there is a [Ionic Warning] in the console output and btw there is also a warning in the console even if I just keep the old style [email protected] codes
    I also tried the code below to keep the html behaves like before and suppress the warning in the console which is just a not-so-beautiful workaround 😅

    <ion-item>
        <ion-label [position]="'stacked'">SomeField<small><i>Optional</i></small></ion-label>
        <ion-input [label]="''" [labelPlacement]="'stacked'" [placeholder]="'please input'"></ion-input>
    </ion-item>
  7. added and removed
    needs: reply
    on Mar 31, 2023
  8. liamdebeasi commented on Apr 3, 2023

    @liamdebeasi
    Contributor

    Are you using aria-labelledby with no Angular binding? (i.e. not using [ariaLabelledBy]).

    Here is an example that uses aria-labelldby without a warning: https://codepen.io/liamdebeasi/pen/PodMEBB

  9. added
    needs: reply
    on Apr 3, 2023
  10. emeryao commented on Apr 6, 2023

    @emeryao
    Author

    Thanks for your advise and I have done another test with the latest @ionic/[email protected] with the code below

    <ion-item>
            <ion-label id="my-label" [position]="'stacked'">SomeField <small><i>Optional</i></small></ion-label>
            <ion-input aria-labelledby="my-label" [placeholder]="'please input'"></ion-input>
    </ion-item>
    

    and it works without any [Ionic Warning] in the console

    but I do not want to assign ids for my ion-label since there is a huge lot of fields in my html and it is a real difficulty to name ids for every fields 😅


    Sorry for the late reply

  11. removed
    needs: reply
    on Apr 6, 2023
  12. 4 remaining items

  13. liamdebeasi commented on Apr 19, 2023

    @liamdebeasi
    Contributor

    Definitely not ideal, but you can do something like this:

    ion-input.custom-input .label-text::after {
      content: "*";
      color: red;
    }
  14. znotdead commented on Apr 19, 2023

    @znotdead

    Definitely not ideal, but you can do something like this:

    ion-input.custom-input .label-text::after {
      content: "*";
      color: red;
    }

    Should issue be reopened? Bug https://bugs.webkit.org/show_bug.cgi?id=172567 for webkit already marked as resolved fixed if you were waiting for it. having id to use 'aria-labelledby' for each input (especially with arrays of forms) make development less pleasant than in ionic 6 and makes migration to 7 more risky.
    In migration there is option to use legacy everywhere (but later will need to migrate anyway), use labelledby everywhere (no point in new style), use mix labelledby and new labels (need to fix css to make it visually match as paddings and text sizes are too different), use for now css ::after (and hope that no other functionality will be needed in future)

  15. liamdebeasi commented on Apr 21, 2023

    @liamdebeasi
    Contributor

    We've had a few people ask about this, so I am going to re-open for visibility. The linked WebKit has been resolved, but it's only applicable to iOS 16. We support back to iOS 14 so there are many iOS users who have not received the WebKit fix.

    If you need complex HTML support we recommend associating an ion-label with ion-input using an aria-labelledby for now until we can introduce better support for HTML labels using the new input syntax.

  16. added
    type: feature request
    package: core
    on Apr 21, 2023
  17. changed the title [-]feat: inline html for label property with [email protected][/-] [+]feat: custom html label for input and textarea with modern form syntax[/+] on Apr 21, 2023
  18. added 2 commits that reference this issue on Jun 15, 2023
    a45395c
    8bcd9e8
  19. liamdebeasi commented on Jun 20, 2023

    @liamdebeasi
    Contributor

    Hi everyone,

    We will be adding experimental support to both ion-input and ion-textarea for custom HTML labels with the modern form syntax. This feature will be available in the next minor release of Ionic, and we will have updated documentation to show how to use it.

    The work required to add this functionality has been completed, so I am going to close this. Thanks!

  20. ionitron-bot commented on Jul 20, 2023

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  21. locked and limited conversation to collaborators on Jul 20, 2023
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

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions