How do I disable/remove ion-ripple effect in ion-button Ioinic 4?
Asked Answered
C

5

12

I need to disable the default ion-ripple-effect in the `ion-button'.

<ion-button>
  <ion-icon slot="icon-only" name="star"></ion-icon>
</ion-button>

enter image description here

I can't disable the pointer-events as I need it.

PS: I've referred the following posts and could not find a proper solution for Ionic 4.

  1. How to remove click effect of an ion-item
  2. Disable ripple effect on element
Cyclotron answered 13/10, 2019 at 8:9 Comment(0)
C
36

--ripple-color CSS variable could be used to turn off the ripple effect.

 <ion-button class="no-ripple">
   <ion-icon slot="icon-only" name="trash"></ion-icon>
 </ion-button>

For example, we could set --ripple-color: transparent on the button, to effectively disable the effect.

.no-ripple {
  --ripple-color: transparent;
}

Refer https://github.com/ionic-team/ionic/issues/19648

Cyclotron answered 20/10, 2019 at 13:55 Comment(2)
It doesn't turn off the ripple effect, it just makes it transparent. For example the margins are still there.Tobey
Yes. That's true. There was no official way to turn it off. This was the sort of recommended solution at that time. Do check the Github issue linked.Cyclotron
S
2

Just set mode to iOS

<ion-button mode='ios'>
Safire answered 5/2, 2020 at 23:19 Comment(0)
B
1

I think it's only included with Android so you can set mode="ios" on the button to avoid that effect.

Yeah so I just checked the source code and it is only used with mode="md" (which is Android / Material Design):

    <TagType
      {...attrs}
      class="button-native"
      disabled={disabled}
      onFocus={this.onFocus}
      onBlur={this.onBlur}
    >
      <span class="button-inner">
        <slot name="icon-only"></slot>
        <slot name="start"></slot>
        <slot></slot>
        <slot name="end"></slot>
      </span>
      {mode === 'md' && <ion-ripple-effect type={this.rippleType}></ion-ripple-effect>}
    </TagType>

That is the only way to do it using the button itself, the rippleType only offers bounded or unbounded, not a way to disable it.

I'm not sure if the ion-ripple-effect can be hidden with css because of the web components encapsulation used in Ionic 4.

Bertabertasi answered 13/10, 2019 at 9:13 Comment(2)
Web components encapsulation makes it tough. However, mode="ios" does the trick. Thanks :DCyclotron
cool, please consider marking as answer if you are happy with it, so others don't waste their time visiting and reading resolved questionsBertabertasi
E
0

In current version on Ionic 4, this is working example:

<ion-button class="submit-btn">...</ion-button>

.submit-btn {
    --background: transparent;
    --background-hover: transparent !important;
}

https://ionicframework.com/docs/api/button#css-custom-properties

Estabrook answered 9/11, 2019 at 17:14 Comment(0)
J
0

If you want to disable ripple effects globally, you can adjust your configuration when you import the IonicModule:

import { IonicModule } from '@ionic/angular';

@NgModule({
  ...
  imports: [
    BrowserModule,
    IonicModule.forRoot({
      rippleEffect: false
    }),
    AppRoutingModule
  ],
  ...
})

Credit to this answer

Janettjanetta answered 20/6, 2024 at 14:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.