You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: ion-select v7 expose label and select container as shadow part #27112
I have searched for existing issues that already include this feature request, without success.
Describe the Feature Request
With new style how labels are defined for form inputs in v7, it would be great if label for ion-select would be exposed as shadow part to allow CSS styling. I am able to style ion-input label but not ion-select.
Describe the Use Case
We need to be able apply CSS styling for labels in our forms. I don't see way how to style ion-select label as it is currently under ion-select #shadowroot.
Describe Preferred Solution
Expose ion-select label same way as already text, icon and placeholder are exposed.
Describe Alternatives
Remove label from ion-select #shadowroot so it is accessible by CSS.
Related Code
No response
Additional Information
No response
Reacted by nihique, Petr Dobřička, Aymeric, Hans, Tomáš Kovářík, Ratcha9, Wasenshi and Mordechai Senderowitz
Can you tell us a little more about what styling customizations you are trying to make with the ion-select label? If you have screenshots/design mocks that would also be very helpful. Thanks!
@sean-perkins
Thank you for response, I will try that.
Our current use case is that we want kind of different look for form for web desktop that ionic provides out of box.
We use fixed position for labels because default position looks bad as inputs are not aligned and we do not want labels above control(stacked/floating which we use for mobiles). So we are trying to achieve the controls alignment as can be seen in attached example (which was WIP in ionic 6 so it was not aligned perfectly yet), but we not were happy with the fixed default width value which causes ellipsis for most longer labels. So we implemented wrapper, that allows us to specify label width as number from 1 to 12 (so we keep 12 columns grid layout that ionic uses as well) and then it overrides width, min-width and max-width on label so the actual controls for fields are aligned under each other.
It was much easier when label was not part of input in legacy mode, I am little afraid that we might need to give up on our goal to have single component that works for both web and mobile.
We use fixed position for labels because default position looks bad as inputs are not aligned
This may be considered a bug in v7. I would need to do a little more investigation, but my initial thoughts are that controls should have similar alignment and spacing (especially when used in an item).
...
We did originally spec shadow parts as part of the feature changes in v7, but cut them due to timing with the release. We are still open to considering them.
To clarify on the problem, the default max width of the label is too low for your application. This causes truncation for long labels. As a result, you would like to increase the width to account for longer labels, so you added the ability to set the width based on the grid size, so that you can have different default widths to account for the labels?
@sean-perkins
Not sure about bug tought, as it seems to work same ways as in v6 in component showcase.
Basically yes.
Increasing max-width to 200px will help with trucation but then it allows the label to have variable width from 100 to 200 based on label content. That will still break the alignment of editable parts. I am quite new to Ionic so maybe it does not make sense to have this possibility. But I am used to Bootstrap forms where you can have labels in one column and the actual inputs start aligned in the other column. So our example for web let say I use label size 3 so all labels will have width 25% of ion-item, so it means all inputs will then have width 75% and they will start under each other. If label is longer than 25% then is fine to ellipsis to maintain the grid aligned.
So maybe for our use case we should stick with 'legacy' mode where we define actual labels and control them and not just pass label text to input?
I'm going to go ahead and classify this as a feature request to get added into our backlog. I do think there is value in exposing the shadow part so that developers can customize the label appearance similar to how they can for input and textareas.
I think more investigation is needed around the fixed label styling. Today, it is focused on aligning the labels in a list, but not for aligning the controls in a list. The appearance of rendering a label alongside a control is also a discouraged practice in certain UI/UX blogs:
It is also a less used display style in popular apps and system design, so we would need more screenshots of other applications before making a determination on if we should change the appearance in Ionic.
Regarding that ui/ux you posted it is mobile focused and I agree that Ionic works for that flawessly. I was hoping (saw some tutorials) that we can use Ionic both for mobile and desktop. I guess we always can create custom components for desktop that will focus on desktop UI/UX that our wrapper could use alongside with ion components but I was trying to avoid that.
@sean-perkins how can we get the label to stack on top of the ion-item or ion-select currently? Do we have to use a label tag above the element like in v6 and use aria-labelledby?
Thank you @sean-perkins and @dobripet for your quick responses! Argh... In the end it was a ViewEncapsulation issue. I don't have a full understanding of how ViewEnapsulation works, but setting the encapsulation in my angular component to ViewEncapsulation.None worked.
Thank you @sean-perkins and @dobripet for your quick responses! Argh... In the end it was a ViewEncapsulation issue. I don't have a full understanding of how ViewEnapsulation works, but setting the encapsulation in my angular component to ViewEncapsulation.None worked.
When you turn off view encapsulation, you are basically exposing the CSS for that particular view to the global Dom. You have to be very careful in doing that. I try never to do this. You may want to use an alternative like NgDeep or creating a custom class in the global state for overrides. View encapsulation basically encapsulates the view as well as the CSS associated with it so it only applies to the view. If you inspect the DOM, you will notice that your custom tag for your component wraps everything inside that view and all of the CSS within the associated stylesheet, for that component gets applied only to that component, but when you turn it off, therefore becomes part of the global scope.
changed the title [-]feat: ion-select v7 expose label as shadow part[/-][+]feat: ion-select v7 expose label and select container as shadow part[/+]on Apr 19, 2023
As the legacy implementation allows for significant styling of the <ion-label>-element, the change to Ionic 7 and Shadow DOM-implementation of labels should definitely expose the label as a Shadow DOM part. Upgrading to Ionic 7 has made a lot of these small design changes we're unable to override again later.
This should also be implemented for ion-checkbox, ion-radio, ion-input, etc. For example, an ion-checkbox with long text will overflow with ellipsis, and there is no way to ensure the text wraps if it's too long.
Please refrain from tagging team members multiple times. The reason why the code snippet does not work is the feature has not been released yet. As I mentioned in #27112 (comment), this feature will be in an upcoming minor release of Ionic.
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.
Activity
sean-perkins commentedon Apr 4, 2023
@dobripet thank you for requesting this feature!
Can you tell us a little more about what styling customizations you are trying to make with the
ion-selectlabel? If you have screenshots/design mocks that would also be very helpful. Thanks!dobripet commentedon Apr 4, 2023
@sean-perkins
Thank you for response, I will try that.
Our current use case is that we want kind of different look for form for web desktop that ionic provides out of box.
We use fixed position for labels because default position looks bad as inputs are not aligned and we do not want labels above control(stacked/floating which we use for mobiles). So we are trying to achieve the controls alignment as can be seen in attached example (which was WIP in ionic 6 so it was not aligned perfectly yet), but we not were happy with the fixed default width value which causes ellipsis for most longer labels. So we implemented wrapper, that allows us to specify label width as number from 1 to 12 (so we keep 12 columns grid layout that ionic uses as well) and then it overrides width, min-width and max-width on label so the actual controls for fields are aligned under each other.
It was much easier when label was not part of input in legacy mode, I am little afraid that we might need to give up on our goal to have single component that works for both web and mobile.
sean-perkins commentedon Apr 4, 2023
@dobripet appreciate the response!
This may be considered a bug in v7. I would need to do a little more investigation, but my initial thoughts are that controls should have similar alignment and spacing (especially when used in an item).
...
We did originally spec shadow parts as part of the feature changes in v7, but cut them due to timing with the release. We are still open to considering them.
To clarify on the problem, the default max width of the label is too low for your application. This causes truncation for long labels. As a result, you would like to increase the width to account for longer labels, so you added the ability to set the width based on the grid size, so that you can have different default widths to account for the labels?
For context, in v7 we set the
max-widthfor the label container to200px: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/input/input.scss#L445dobripet commentedon Apr 4, 2023
@sean-perkins
Not sure about bug tought, as it seems to work same ways as in v6 in component showcase.
Basically yes.
Increasing max-width to 200px will help with trucation but then it allows the label to have variable width from 100 to 200 based on label content. That will still break the alignment of editable parts. I am quite new to Ionic so maybe it does not make sense to have this possibility. But I am used to Bootstrap forms where you can have labels in one column and the actual inputs start aligned in the other column. So our example for web let say I use label size 3 so all labels will have width 25% of ion-item, so it means all inputs will then have width 75% and they will start under each other. If label is longer than 25% then is fine to ellipsis to maintain the grid aligned.
So maybe for our use case we should stick with 'legacy' mode where we define actual labels and control them and not just pass label text to input?
sean-perkins commentedon Apr 4, 2023
I'm going to go ahead and classify this as a feature request to get added into our backlog. I do think there is value in exposing the shadow part so that developers can customize the label appearance similar to how they can for input and textareas.
I think more investigation is needed around the fixed label styling. Today, it is focused on aligning the labels in a list, but not for aligning the controls in a list. The appearance of rendering a label alongside a control is also a discouraged practice in certain UI/UX blogs:
Source: https://uiuxtrend.com/5-ui-ux-tips-mobile-form-design-best-practices/
It is also a less used display style in popular apps and system design, so we would need more screenshots of other applications before making a determination on if we should change the appearance in Ionic.
For reference, this is the element we should expose with the shadow part: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/select/select.tsx#L704
dobripet commentedon Apr 4, 2023
@sean-perkins
Thank you.
Regarding that ui/ux you posted it is mobile focused and I agree that Ionic works for that flawessly. I was hoping (saw some tutorials) that we can use Ionic both for mobile and desktop. I guess we always can create custom components for desktop that will focus on desktop UI/UX that our wrapper could use alongside with ion components but I was trying to avoid that.
judsonmusic commentedon Apr 4, 2023
@sean-perkins how can we get the label to stack on top of the ion-item or ion-select currently? Do we have to use a label tag above the element like in v6 and use aria-labelledby?
What i was used to doing:
Which resulted in:

But with the new syntax:
My UX team wants the labels back on top of the inputs. How can I achieve this in v7 current state?
7 remaining items
ntorrey commentedon Apr 17, 2023
Thank you @sean-perkins and @dobripet for your quick responses! Argh... In the end it was a ViewEncapsulation issue. I don't have a full understanding of how ViewEnapsulation works, but setting the encapsulation in my angular component to ViewEncapsulation.None worked.
judsonmusic commentedon Apr 17, 2023
When you turn off view encapsulation, you are basically exposing the CSS for that particular view to the global Dom. You have to be very careful in doing that. I try never to do this. You may want to use an alternative like NgDeep or creating a custom class in the global state for overrides. View encapsulation basically encapsulates the view as well as the CSS associated with it so it only applies to the view. If you inspect the DOM, you will notice that your custom tag for your component wraps everything inside that view and all of the CSS within the associated stylesheet, for that component gets applied only to that component, but when you turn it off, therefore becomes part of the global scope.
[-]feat: ion-select v7 expose label as shadow part[/-][+]feat: ion-select v7 expose label and select container as shadow part[/+]feat(select): expose container and label as CSS parts (#27541)
br0ll commentedon Jun 2, 2023
As the legacy implementation allows for significant styling of the
<ion-label>-element, the change to Ionic 7 and Shadow DOM-implementation of labels should definitely expose the label as a Shadow DOM part. Upgrading to Ionic 7 has made a lot of these small design changes we're unable to override again later.br0ll commentedon Jun 2, 2023
This should also be implemented for ion-checkbox, ion-radio, ion-input, etc. For example, an ion-checkbox with long text will overflow with ellipsis, and there is no way to ensure the text wraps if it's too long.
liamdebeasi commentedon Jun 8, 2023
Hi everyone,
We implemented this in #27541. This feature will be available in an upcoming minor release of Ionic.
mingxin-yang commentedon Jun 16, 2023
#27392 (comment) i want to use this, i use 7.0.14, but your method is not for me good @liamdebeasi
mingxin-yang commentedon Jun 18, 2023
#27242 (comment) It's don't work
mingxin-yang commentedon Jun 18, 2023
@liamdebeasi
liamdebeasi commentedon Jun 20, 2023
Please refrain from tagging team members multiple times. The reason why the code snippet does not work is the feature has not been released yet. As I mentioned in #27112 (comment), this feature will be in an upcoming minor release of Ionic.
mingxin-yang commentedon Jun 20, 2023
Sorry, thank you for your reply, I thought you were talking about version 7.0.14, sorry
ionitron-bot commentedon 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.