Skip to content

bug: no way to set color for <ion-input label> - request for @labelColor #27326

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
trakhimenok opened this issue Apr 28, 2023 · 9 comments
Closed
3 tasks done
Labels

Comments

@trakhimenok
Copy link

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

Looks like the new implementation is a regression and we lose ability to customize label styling.

With new way of setting labels for inputs (ion-input, ion-select, etc) there is seems no way to set color for labels.

Previously:

<ion-item>
  <ion-label color=medium>My label<ion-label>
  <ionp input />
</ion-input>

image

Now

<ion-item>
  <ion-input label="My label"/>
</ion-input>

image

Expected Behavior

I believe an attribute labelColor should be provided to customize label.

This should be applied for all inputs that take label (ion-input, ion-select, ion-radio, etc)

Steps to Reproduce

Simply check new label vs old with color.

Code Reproduction URL

No response

Ionic Info

I'm using NX so for some reason ionic info is not very informative:

➜  src git:(main) ✗ ionic info
[WARN] You are not in an Ionic project directory. Project context may be missing.

Ionic:

   Ionic CLI : 5.4.16

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   NodeJS : v18.2.0
   npm    : 8.9.0
   OS     : macOS Unknown

Additional Information

It would be good to know what is the reason for the change.

@ionitron-bot ionitron-bot bot added the triage label Apr 28, 2023
@liamdebeasi liamdebeasi self-assigned this Apr 28, 2023
@liamdebeasi
Copy link
Contributor

Thanks for the report. You can set the label color already in Ionic: https://codepen.io/liamdebeasi/pen/mdzwNJa

Is there something that is not working on your end?

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

@liamdebeasi this would work.

I just have not found this way in documentation. Is .label-text class documented anywhere?

I also kinda liked the way to set colors through ionic's color attribute but I can live with a custom class.

I'll give it a try over the weekend.

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

The internal structure of our components are not documented currently, but you can interact with .label-text in your preferred browser development tools.

As for components where you pass the label text directly inside of the component (i.e. checkbox, toggle, radio, etc) you can definitely continue to use ion-label to get the color behavior as long as you are passing the label inside of the component:

<!-- Not Recommended -->
<ion-label color="danger">My Label</ion-label>
<ion-radio></ion-radio>

<!-- Recommended -->
<ion-radio>
  <ion-label color="danger">My Label</ion-label>
</ion-radio>

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

The warning says should not be used at all:

[Ionic Warning]: ion-radio now requires providing a label with either the default slot or the "aria-label" attribute. To migrate, remove any usage of "ion-label" and pass the label text to either the component or the "aria-label" attribute.

Example: <ion-radio>Option Label</ion-radio>
Example with aria-label: <ion-radio aria-label="Option Label"></ion-radio>

Developers can use the "legacy" property to continue using the legacy form markup. This property will be removed in an upcoming major release of Ionic where this form control will use the modern form markup. 

If we still can use ion-label inside controls probably should be changed.

Can I also pass ion-label inside ion-input & ion-textarea?

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

The warning says should not be used at all:

Yeah that warning is a bit confusing. I'll look into clarifying that.

Can I also pass ion-label inside ion-input & ion-textarea?

Not at the moment. See #27061.

@trakhimenok
Copy link
Author

Liam, below worked for me:

.sneat-label-color-medium .label-text {
  color: #92949c;
}

<ion-input class="sneat-label-color-medium" [label]="labelText()" labelPlacement="fixed"

But I wonder how to account for themes (dark/light)? Below does NOT work for me.

.sneat-label-color-medium .label-text {
	color: var(--ion-color-medium);
}

Previously <ion-label color=medium> would handle theming.

@liamdebeasi
Copy link
Contributor

Is --ion-color-medium defined?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label May 1, 2023
@ionitron-bot ionitron-bot bot removed the triage label May 1, 2023
@trakhimenok
Copy link
Author

You right, the variables file was not added to the app I've tested.

The --ion-color-medium works fine with custom CSS class. Closing this.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels May 4, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Jun 3, 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 Jun 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants