Skip to content

feat: Wrap label text in ion-select, ion-toggle and other input components #27621

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
tetsuwanadam opened this issue Jun 8, 2023 · 3 comments
Closed
3 tasks done
Labels

Comments

@tetsuwanadam
Copy link

tetsuwanadam commented Jun 8, 2023

Prerequisites

Describe the Feature Request

With the v7 syntax for setting an ion-select label via the label property, or an ion-toggle label via its inner text, it appears impossible to make long label text wrap instead of being truncated.

The fix using the previous syntax would be:

<ion-item>
	<ion-label class="ion-text-wrap">Long ion-select label that will wrap</ion-label>
	<ion-select>
		<!-- Select options here -->
	</ion-select>
</ion-item>

<ion-item>
	<ion-label class="ion-text-wrap">Long ion-toggle label that will wrap</ion-label>
	<ion-toggle></ion-toggle>
</ion-item>

Describe the Use Case

Long label text in select, toggle and other input elements sometimes needs to wrap instead of being truncated.

Describe Preferred Solution

Potential solutions would include:

  • Making the ion-text-wrap class apply to the ion-select or ion-toggle component's label
  • Implementing a css custom property for wrapping the label text
  • Exposing the label as a shadow part, as requested in issue 27112

Describe Alternatives

No response

Related Code

No response

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Jun 8, 2023
@tetsuwanadam tetsuwanadam changed the title feat: Wrap label text in ion-select and other input components feat: Wrap label text in ion-select, ion-toggle and other input components Jun 8, 2023
@liamdebeasi liamdebeasi self-assigned this Jun 8, 2023
@liamdebeasi
Copy link
Contributor

liamdebeasi commented Jun 8, 2023

Thanks for the report. With the exception of one component, you can already get the label text to wrap:

  1. ion-checkbox, ion-toggle, ion-radio, ion-range:

These components support passing in custom HTML as the label. This means you can use the ion-text-wrap class currently to make the text wrap.

Example:

<!-- the 300px width is just to emphasize the overflow. You don't need to use 300px for this to work -->
<ion-toggle style="width: 300px">
  <div class="ion-text-wrap">This is my really really really really really long text</div>
</ion-toggle>
  1. ion-select:

Currently this is difficult to do. However, we have implemented both #27112 and #26838 which will make this much easier to do.

These features will be in the next minor release of Ionic.

Example usage once this feature ships:

<!-- the 300px width is just to emphasize the overflow. You don't need to use 300px for this to work -->
<!-- You can also use the shadow part -->
<ion-select style="width: 300px">
  <div slot="label" class="ion-text-wrap">This is my really really really really really long text</div>
</ion-select>
  1. ion-input and ion-textarea:

You can set the text wrapping by using CSS since these components do not use the shadow DOM:

<ion-input
  class="my-input" 
  style="width: 300px" 
  label="This is my really really really really really long text"
></ion-input>
.my-input .label-text {
  white-space: normal;
}

However, I recognize this is an inconsistent developer experience. We plan to implement #27061 which will let you pass custom HTML as the label. Once this feature ships the behavior will be consistent.

Example usage once this feature ships:

<!-- the 300px width is just to emphasize the overflow. You don't need to use 300px for this to work -->
<!-- Note: The previous approach still works too -->
<ion-input style="width: 300px">
  <div slot="label" class="ion-text-wrap">This is my really really really really really long text</div>
</ion-input>

I am going to close this in favor of #27061 since that is the outstanding feature required to make this behavior consistent. Let me know if you have questions.

@liamdebeasi liamdebeasi closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2023
@liamdebeasi liamdebeasi removed their assignment Jun 8, 2023
@liamdebeasi
Copy link
Contributor

Also we've gotten this question a couple times so I think it makes sense to add some playgrounds on our docs that show how to do this.

@ionitron-bot
Copy link

ionitron-bot bot commented Jul 27, 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 27, 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