Skip to content

bug: Label not aligned properly between ion input and ion select when in card component #27086

Closed

Description

@judsonmusic

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

Notice in the screen shot when every i put inputs inside of an ion card side by side the select label is pushed down by a few pixels.
image

Code:

 <form>
    <ion-card #cardmedtype>
      <ion-card-header color="primary">
        <ion-card-title><strong>Choose a Medication Type</strong></ion-card-title>
      </ion-card-header>
      <ion-card-content>
        <ion-grid>
          <ion-row>
            <ion-col>
              <ion-item>
                <ion-input label="input" labelPlacement="stacked"></ion-input>
              </ion-item>
            </ion-col>
            <ion-col>
              <ion-item>
                <ion-select label="select" labelPlacement="stacked"></ion-select>
              </ion-item>
            </ion-col>
          </ion-row>
        </ion-grid>
      </ion-card-content>
    </ion-card>
  </form>

However removing it from the ion card solves the issue.

image

Code:

  <form>
    <ion-grid>
      <ion-row>
        <ion-col>
          <ion-item>
            <ion-input label="input" labelPlacement="stacked"></ion-input>
          </ion-item>
        </ion-col>
        <ion-col>
          <ion-item>
            <ion-select label="select" labelPlacement="stacked"></ion-select>
          </ion-item>
        </ion-col>
      </ion-row>
    </ion-grid>
  </form>

Expected Behavior

I should be able to see the labels aligned on the same horizontal axis regardless of whether or not they are in a card.

Steps to Reproduce

Create ion input with label and ion select with label side by side using ion-col (grid)
You will see the label are aligned horizontally.
However inside a card this is not the case.

https://stackblitz.com/edit/ionic7-label-test?file=src/app/app.component.html

image

My workaround for now...

import { Directive, ElementRef } from '@angular/core';

@Directive({
  standalone: true,
  selector: 'ion-select'
})
export class SelectLabelFixDirective {
  constructor(private el: ElementRef) {
    // console.warn('We have an ion select!', el.nativeElement);
    const shadowRoot: DocumentFragment = this.el.nativeElement.shadowRoot;
    if (shadowRoot) {
      // console.warn('Fix Stacked Element Nested.: ', shadowRoot);
      var style = document.createElement('style');
      style.innerHTML = '.select-wrapper{ line-height: 18px; }';
      shadowRoot.appendChild(style);
    }
  }
}

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 7.0.0 (/Users/asd/.nvm/versions/node/v16.18.0/lib/node_modules/@ionic/cli)
Ionic Framework : not installed
@angular-devkit/build-angular : 15.2.4
@angular-devkit/schematics : 15.2.4
@angular/cli : 15.2.4
@ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 4.6.1
@capacitor/android : 4.6.1
@capacitor/core : 4.6.1
@capacitor/ios : 4.6.1

Utility:

cordova-res : 0.15.4
native-run (update available: 1.7.2) : 1.7.1

System:

NodeJS : v16.18.0 (/Users/asd/.nvm/versions/node/v16.18.0/bin/node)
npm : 9.6.2
OS : macOS Unknown

Additional Information

No response

Activity

  1. changed the title [-]bug: Label not aligned properly between ion input and ion select.[/-] [+]bug: Label not aligned properly between ion input and ion select when in card component[/+] on Apr 2, 2023
  2. judsonmusic commented on Apr 2, 2023

    @judsonmusic
    Author

    @sean-perkins this is a good one for you :) My work around is sketchy but it works. Hope this can get solved. Super weird.

  3. self-assigned this
    on Apr 3, 2023
  4. liamdebeasi commented on Apr 3, 2023

    @liamdebeasi
    Contributor

    Thanks for the report. It looks like the ion-card line height styles are being inherited to ion-select.

    Our global normalize styles applies line-height: normal to label elements:

    line-height: normal;

    This works for ion-input because the <label> is in the Light DOM. The label on ion-select is in the Shadow DOM.

    To fix this we should probably apply line-height: normal to the labels on input, textarea, and select. (There should be no visible change to input/textarea, but this avoids the issue in the event we move those components to use the Shadow DOM in the future)

  5. added
    package: core
    type: bug
    on Apr 3, 2023
  6. removed their assignment
    on Apr 3, 2023
  7. ionitron-bot commented on May 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.

  8. locked and limited conversation to collaborators on May 20, 2023
  9. added a commit that references this issue on Jan 26, 2024
    5a2b87c
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: bug

    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