ion-label component inside the stencil-component-starter not getting rendered

倾然丶 夕夏残阳落幕 提交于 2019-12-04 09:58:12

You would need to either explicitly import '@ionic/core'; in your stencil-component-starter component or add CDN scripts/styles to the index.html. I remember at one point either the toolkit or stencil-app-starter specifically had that import in a root element with an earlier version of @ionic/core beta or even an alpha.

Also, per documentation, you would also need to wrap the ion-range with ion-item as well as using slot="start" and slot="end" instead of range-left and range-right.

import { Component, Prop } from '@stencil/core';
import '@ionic/core';

@Component({
  tag: 'my-component',
  styleUrl: 'my-component.css',
  shadow: true
})
export class MyComponent {

  @Prop() first: string;
  @Prop() last: string;
  @Prop() minHeartRate: number;
  @Prop() maxHeartRate: number;

  render() {
    return (
      <div>
        Athlete: {this.first} {this.last} - Heart Rate Range:
        <ion-item>
          <ion-range mode="ios" dualKnobs={true} min={0} max={200} step={2} pin={true} snaps={true} value={{lower: this.minHeartRate, upper: this.maxHeartRate}}>
            <ion-label slot="start">0</ion-label>
            <ion-label slot="end">200</ion-label>
          </ion-range>
        </ion-item>
      </div>
    );
  }
}

This will help ensure the styles are injected and the component renders properly. In all fairness, when I tried this, most of the styles came through, but there were definitely issues with the positioning of the slotted ion-label elements. There would definitely need to be some adjustments to the styling including flex grow/shrink/basis as well as positioning/margin of the end slot element. It is probably wise to submit the styling issues at @ionic/core github as well.

Hopefully that helps!

based on the latest 4.0 beta... I still do think there is a bug in the styling of the labels by default, but this is a work-around

reference to the doc since stencil uses ionic v4 - https://beta.ionicframework.com/docs/api/range

<ion-range mode="ios" 
           dualKnobs={true} 
           min={0} max={200} 
           step={2} pin={true} 
           snaps={true} 
           value={{lower: 89, upper: 150}}>
   <ion-label slot="start" style={{flex: 'none',padding:'10px'}}>0</ion-label>
   <ion-label slot="end" style={{flex: 'none',padding:'10px'}}>200</ion-label>
</ion-range>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!