Skip to content

Commit

Permalink
fix(segment): remove duplicate ripple effect on pointerup (#27448)
Browse files Browse the repository at this point in the history
Issue number: resolves #27338

---------

## What is the current behavior?
Segment button on `md` mode shows two ripple effects: once on
pointerdown and again on pointerup

## What is the new behavior?
Segment button on `md` mode only shows a ripple effect on pointerdown

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

---------

Co-authored-by: Brandy Carney <brandy@ionic.io>
  • Loading branch information
GlenOttley and brandyscarney committed May 24, 2023
1 parent 02678f3 commit 01f9959
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions core/src/components/segment/segment.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { ComponentInterface, EventEmitter } from '@stencil/core';
import { Component, Element, Event, Host, Listen, Prop, State, Watch, h, writeTask } from '@stencil/core';

import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';
import type { Color, StyleEventDetail } from '../../interface';
import type { Gesture, GestureDetail } from '../../utils/gesture';
import { pointerCoord } from '../../utils/helpers';
import { isRTL } from '../../utils/rtl';
import { createColorClasses, hostContext } from '../../utils/theme';

Expand Down Expand Up @@ -194,14 +192,10 @@ export class Segment implements ComponentInterface {
onEnd(detail: GestureDetail) {
this.setActivated(false);

const checkedValidButton = this.setNextIndex(detail, true);
this.setNextIndex(detail, true);

detail.event.stopImmediatePropagation();

if (checkedValidButton) {
this.addRipple(detail);
}

const value = this.value;
if (value !== undefined) {
if (this.valueBeforeGesture !== value) {
Expand Down Expand Up @@ -230,32 +224,6 @@ export class Segment implements ComponentInterface {
return this.getButtons().find((button) => button.value === this.value);
}

/**
* The gesture blocks the segment button ripple. This
* function adds the ripple based on the checked segment
* and where the cursor ended.
*/
private addRipple(detail: GestureDetail) {
const useRippleEffect = config.getBoolean('animated', true) && config.getBoolean('rippleEffect', true);
if (!useRippleEffect) {
return;
}

const buttons = this.getButtons();
const checked = buttons.find((button) => button.value === this.value)!;

const root = checked.shadowRoot || checked;
const ripple = root.querySelector('ion-ripple-effect');

if (!ripple) {
return;
}

const { x, y } = pointerCoord(detail.event);

ripple.addRipple(x, y).then((remove) => remove());
}

/*
* Activate both the segment and the buttons
* due to a bug with ::slotted in Safari
Expand Down

0 comments on commit 01f9959

Please sign in to comment.