question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: ion-select / ion-label not displayed properly with attribute floating

See original GitHub issue

#19712 Bug Report

Ionic version: [x] **4.11.3

Current behavior: When using ion-select inside and ion-item, the ion-label (with floating attribute) is displayed on top of the selected value of the ion-select

image

Expected behavior: The label shall be displayed with small font upper

Related code:

        <ion-item>
          <ion-label position="floating">Event Game</ion-label>
          <ion-select [(ngModel)]="selectedGame.key" (ionChange)="onChangeGame()">
            <ion-select-option *ngFor="let game of gameLst" [value]="game.key">{{game.value}}</ion-select-option>
          </ion-select>
        </ion-item>

Here is a project showing the issue: https://github.com/eltoky/tstSelect

Ionic info:

Ionic:

   Ionic CLI                     : 5.4.6 (/Users/x/.nvm/versions/node/v10.16.0/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.11.3
   @angular-devkit/build-angular : 0.802.2
   @angular-devkit/schematics    : 8.3.17
   @angular/cli                  : 8.3.17
   @ionic/angular-toolkit        : 2.1.1

Capacitor:

   Capacitor CLI   : 1.3.0
   @capacitor/core : 1.3.0

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : none
   Cordova Plugins   : no whitelisted plugins (0 plugins total)

Utility:

   cordova-res : not installed
   native-run  : 0.2.7 (update available: 0.2.9)

System:

   NodeJS : v10.16.0 (/Users/x/.nvm/versions/node/v10.16.0/bin/node)
   npm    : 6.13.0
   OS     : macOS Mojave
   Xcode  : Xcode 11.2.1 Build version 11B500

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
olaisen81commented, Aug 26, 2021

Hi, i’ve got the same issue with latest angular (12.2.2) and ionic (5.6.14) version, any update or fix? For now i resolved applying item-has-value class to item parent element, but it’s a temporary workaround:

ngAfterViewInit(): void { this.ionSelectPosizione.el.parentElement.classList.add("item-has-value"); }

1reaction
Giwayumecommented, Apr 16, 2021

@brandyscarney

Here’s a simple 20 line reproduction on the latest version 5.6.4, vanilla Javascript, no Angular involved here.

https://jsfiddle.net/e2t31qaw/

The order of events matters. What seems to cause this bug specifically is:

  1. Initializing the ion-select (doesn’t matter what options/values are passed).
  2. Waiting an arbitrary amount of time, in this case 100ms.
  3. Clearing out the list of options on the ion-select (if there are any). select.innerHTML = '';
  4. Setting the “value” attribute on the “ion-select” before any options are added. select.setAttribute('value', 'option1');
  5. Creating the ion-select-option elements and appending them to the ion-select afterwards.

The jsfiddle link above shows this: image

Read more comments on GitHub >

github_iconTop Results From Across the Web

bug: ion-select / ion-label not displayed properly with attribute ...
It seems to be a problem (yet, in Ionic 6.0.2) when the scenario is: use of dynamic items (using ngFor, for instance to...
Read more >
ion-select / ion-label not displayed properly with attribute ...
That way the pre-selected value shows and the label is floated like expected. So, try: <ion-select [(ngModel)]="tstObj.key" (ionChange)= ...
Read more >
ion-select / ion-label not displayed properly with attribute ...
Best coding solution for query ion-select / ion-label not displayed properly with attribute floating in Ionic 4.
Read more >
ion-datetime - Ionic Framework
Datetimes present a picker interface to select dates and times. Ionic's API Datetime input component easily displays a preferred format, and manages values....
Read more >
Advanced Forms & Validation in Ionic & Angular | Josh Morony
We must also set the formGroup property on the parent <form> to have the ... <ion-label position="floating">Privacy</ion-label> <ion-select ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found