Ionic 4:离子芯片默认可激活/可点击;如何关闭?
Ionic 4: ion-chip activatable / clickable by default; how to turn off?
将 Ionic 4 与 React 结合使用,我有以下代码:
<IonChip color="success">
<IonIcon icon={thumbsUp} />
<IonLabel>{this.state.numCorrect}</IonLabel>
</IonChip>
默认情况下,这会在我的浏览器中呈现以下 DOM 内容:
<ion-chip color="success" class="ion-color ion-color-success ios ion-activatable hydrated">
<ion-icon role="img" class="ios hydrated"> ... </ion-icon>
<ion-label class="sc-ion-label-ios-h sc-ion-label-ios-s ios hydrated">0</ion-label>
</ion-chip>
如您所见,ion-activatable
class 被自动添加到芯片组件,这导致它看起来可点击并显示 Material 设计涟漪效应等. 但我不希望这个组件是可点击的(我只是将它用作指示器组件)。我可以以某种方式禁用此 class 吗?
Ionic 4 的联机文档对此没有提供任何建议。
如果你查看ion-chip
Webcomponent的implemetation,可以看到默认添加了ion-activatable
class(你只能修改class和组件渲染后的事件):
export class Chip implements ComponentInterface {
/**
* The color to use from your application's color palette.
* Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
* For more information on colors, see [theming](/docs/theming/basics).
*/
@Prop() color?: Color;
/**
* Display an outline style button.
*/
@Prop() outline = false;
render() {
const mode = getIonMode(this);
return (
<Host
class={{
...createColorClasses(this.color),
[mode]: true,
'chip-outline': this.outline,
'ion-activatable': true,
}}
>
<slot></slot>
{mode === 'md' && <ion-ripple-effect></ion-ripple-effect>}
</Host>
);
}
}
所以你可以做一个简单的解决方法,就是用 pointer-events
CSS 属性(和如果你不想渲染涟漪效应,只做 <IonChip mode="ios">
:
ion-chip {
pointer-events: none;
}
将 Ionic 4 与 React 结合使用,我有以下代码:
<IonChip color="success">
<IonIcon icon={thumbsUp} />
<IonLabel>{this.state.numCorrect}</IonLabel>
</IonChip>
默认情况下,这会在我的浏览器中呈现以下 DOM 内容:
<ion-chip color="success" class="ion-color ion-color-success ios ion-activatable hydrated">
<ion-icon role="img" class="ios hydrated"> ... </ion-icon>
<ion-label class="sc-ion-label-ios-h sc-ion-label-ios-s ios hydrated">0</ion-label>
</ion-chip>
如您所见,ion-activatable
class 被自动添加到芯片组件,这导致它看起来可点击并显示 Material 设计涟漪效应等. 但我不希望这个组件是可点击的(我只是将它用作指示器组件)。我可以以某种方式禁用此 class 吗?
Ionic 4 的联机文档对此没有提供任何建议。
如果你查看ion-chip
Webcomponent的implemetation,可以看到默认添加了ion-activatable
class(你只能修改class和组件渲染后的事件):
export class Chip implements ComponentInterface {
/**
* The color to use from your application's color palette.
* Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
* For more information on colors, see [theming](/docs/theming/basics).
*/
@Prop() color?: Color;
/**
* Display an outline style button.
*/
@Prop() outline = false;
render() {
const mode = getIonMode(this);
return (
<Host
class={{
...createColorClasses(this.color),
[mode]: true,
'chip-outline': this.outline,
'ion-activatable': true,
}}
>
<slot></slot>
{mode === 'md' && <ion-ripple-effect></ion-ripple-effect>}
</Host>
);
}
}
所以你可以做一个简单的解决方法,就是用 pointer-events
CSS 属性(和如果你不想渲染涟漪效应,只做 <IonChip mode="ios">
:
ion-chip {
pointer-events: none;
}