Skip to content

feat: ion-select v7 expose label and select container as shadow part #27112

Closed

Description

@dobripet

Prerequisites

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

Activity

  1. sean-perkins commented on Apr 4, 2023

    @sean-perkins
    Contributor

    @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-select label? If you have screenshots/design mocks that would also be very helpful. Thanks!

  2. added
    needs: reply
    on Apr 4, 2023
  3. dobripet commented on Apr 4, 2023

    @dobripet
    Author

    @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.

    image

  4. added and removed
    needs: reply
    on Apr 4, 2023
  5. sean-perkins commented on Apr 4, 2023

    @sean-perkins
    Contributor

    @dobripet appreciate the response!

    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?

    For context, in v7 we set the max-width for the label container to 200px: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/input/input.scss#L445

  6. dobripet commented on Apr 4, 2023

    @dobripet
    Author

    @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?

  7. sean-perkins commented on Apr 4, 2023

    @sean-perkins
    Contributor

    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:

    Label placement UI trend

    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

  8. added
    type: feature request
    package: core
    on Apr 4, 2023
  9. dobripet commented on Apr 4, 2023

    @dobripet
    Author

    @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.

  10. judsonmusic commented on Apr 4, 2023

    @judsonmusic

    @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:

    <ion-col>
        <ion-item>
            <ion-label position="stacked">Unit</ion-label>
             <ion-select required formControlName="medunits" placeholder="Please Select">
              <ion-select-option [value]="msm.medunitid" *ngFor="let msm of medicationUnits">{{msm.medunit}}</ion-select-option>
        </ion-select>
      </ion-item>
    </ion-col>
    

    Which resulted in:
    image

    But with the new syntax:

    <ion-col>
        <ion-item>
          <ion-select required label="Unit" labelPlacement="stacked" formControlName="medunits" placeholder="Please Select">
            <ion-select-option [value]="msm.medunitid" *ngFor="let msm of medicationUnits">{{msm.medunit}}</ion-select-option>
          </ion-select>
       </ion-item>
    </ion-col>
    

    image

    My UX team wants the labels back on top of the inputs. How can I achieve this in v7 current state?

  11. 7 remaining items

  12. ntorrey commented on Apr 17, 2023

    @ntorrey

    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.

  13. judsonmusic commented on Apr 17, 2023

    @judsonmusic

    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.

  14. 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
  15. added a commit that references this issue on May 24, 2023
    5c10f88
  16. br0ll commented on Jun 2, 2023

    @br0ll

    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.

  17. br0ll commented on Jun 2, 2023

    @br0ll

    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.

  18. liamdebeasi commented on Jun 8, 2023

    @liamdebeasi
    Contributor

    Hi everyone,

    We implemented this in #27541. This feature will be available in an upcoming minor release of Ionic.

  19. mingxin-yang commented on Jun 16, 2023

    @mingxin-yang

    #27392 (comment) i want to use this, i use 7.0.14, but your method is not for me good @liamdebeasi

  20. mingxin-yang commented on Jun 18, 2023

    @mingxin-yang

    #27242 (comment) It's don't work

  21. mingxin-yang commented on Jun 18, 2023

    @mingxin-yang
  22. liamdebeasi commented on Jun 20, 2023

    @liamdebeasi
    Contributor

    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.

  23. mingxin-yang commented on Jun 20, 2023

    @mingxin-yang

    Sorry, thank you for your reply, I thought you were talking about version 7.0.14, sorry

  24. 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.

  25. 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