Skip to content

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

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

Closed
3 tasks done
emeryao opened this issue Mar 30, 2023 · 11 comments
Closed
3 tasks done

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

emeryao opened this issue Mar 30, 2023 · 11 comments
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement

Comments

@emeryao
Copy link

emeryao commented Mar 30, 2023

Prerequisites

Describe the Feature Request

Inline html template for label on ion-input

Describe the Use Case

with ionic@6.x 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 ionic@7.x 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

@ionitron-bot ionitron-bot bot added the triage label Mar 30, 2023
@emeryao emeryao changed the title feat: inline html for label property feat: inline html for label property with ionic@7.x Mar 30, 2023
@liamdebeasi liamdebeasi self-assigned this Mar 30, 2023
@liamdebeasi
Copy link
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?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Mar 30, 2023
@liamdebeasi liamdebeasi removed their assignment Mar 30, 2023
@ionitron-bot ionitron-bot bot removed the triage label Mar 30, 2023
@emeryao
Copy link
Author

emeryao commented Mar 31, 2023

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 ionic@6.x 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>

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Mar 31, 2023
@liamdebeasi
Copy link
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

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Apr 3, 2023
@ionitron-bot ionitron-bot bot removed the triage label Apr 3, 2023
@emeryao
Copy link
Author

emeryao commented Apr 6, 2023

Thanks for your advise and I have done another test with the latest @ionic/angular@7.0.1 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

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Apr 6, 2023
@liamdebeasi
Copy link
Contributor

Manually associating the input with the label is our recommended approach right now. Unfortunately, we are not able to add custom HTML support to ion-input at this time due to the WebKit bug I mentioned in #27061 (comment). Once the fix for that bug has been available for a time, we do plan to look into moving ion-input and ion-textarea to use the Shadow DOM which would allow for custom HTML support.

I am going to close this for now, but let me know if you have questions.

@liamdebeasi liamdebeasi closed this as not planned Won't fix, can't repro, duplicate, stale Apr 6, 2023
@znotdead
Copy link

At least update documentation about how to make html work in labels. Haven't found one.
My use case is red asterisk to required field labels. Is there functionality for that?
Having some inputs with new design and some with old ion-label and aria-labelledby will result inconsistency in text sizes and paddings. Definitely not production view out of box.

@liamdebeasi
Copy link
Contributor

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

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

@znotdead
Copy link

znotdead commented Apr 19, 2023

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)

@liamdebeasi
Copy link
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.

@liamdebeasi liamdebeasi reopened this Apr 21, 2023
@liamdebeasi liamdebeasi added type: feature request a new feature, enhancement, or improvement package: core @ionic/core package labels Apr 21, 2023
@liamdebeasi liamdebeasi changed the title feat: inline html for label property with ionic@7.x feat: custom html label for input and textarea with modern form syntax Apr 21, 2023
liamdebeasi added a commit that referenced this issue Jun 15, 2023
Issue number: resolves #27061

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Input does not accept custom HTML labels

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Input accepts custom HTML labels as an experimental feature. We marked
this as experimental because it makes use of "scoped slots" which is an
emulated version of Web Component slots. As a result, there may be
instances where the slot behavior does not exactly match the native slot
behavior.

Note to reviewers: This is a combination of previously reviewed PRs. The
implementation is complete, so feel free to bikeshed.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->


Docs PR: ionic-team/ionic-docs#2997

---------

Co-authored-by: Brandy Carney <brandyscarney@users.noreply.github.com>
liamdebeasi added a commit that referenced this issue Jun 20, 2023
Issue number: resolves #27061

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Textarea does not accept custom HTML labels

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Textarea accepts custom HTML labels as an experimental feature. We
marked this as experimental because it makes use of "scoped slots" which
is an emulated version of Web Component slots. As a result, there may be
instances where the slot behavior does not exactly match the native slot
behavior.

Note to reviewers: This is a combination of previously reviewed PRs. The
implementation is complete, so feel free to bikeshed.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->


Docs PR: ionic-team/ionic-docs#3001

---------

Co-authored-by: ionitron <hi@ionicframework.com>
@liamdebeasi
Copy link
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!

@ionitron-bot
Copy link

ionitron-bot bot commented Jul 20, 2023

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.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

3 participants