fix(segment): add activated class directly to segment button (#20400)

this gets around a bug with Safari where the ::slotted css selector was not working properly
This commit is contained in:
Brandy Carney
2020-02-07 12:13:09 -05:00
committed by GitHub
parent fd1b44a40b
commit e8886e98f1
4 changed files with 23 additions and 13 deletions

View File

@ -23,14 +23,6 @@
}
// Segment: Activated
// --------------------------------------------------
:host(.segment-activated) ::slotted(ion-segment-button) {
--indicator-transform: scale(0.95);
}
// Segment: Default Toolbar
// --------------------------------------------------

View File

@ -123,7 +123,7 @@ export class Segment implements ComponentInterface {
}
onEnd(detail: GestureDetail) {
this.activated = false;
this.setActivated(false);
const checkedValidButton = this.setNextIndex(detail, true);
@ -157,6 +157,23 @@ export class Segment implements ComponentInterface {
ripple.addRipple(x, y).then(remove => remove());
}
/*
* Activate both the segment and the buttons
* due to a bug with ::slotted in Safari
*/
private setActivated(activated: boolean) {
const buttons = this.getButtons();
buttons.forEach(button => {
if (activated) {
button.classList.add('segment-button-activated');
} else {
button.classList.remove('segment-button-activated');
}
});
this.activated = activated;
}
private activate(detail: GestureDetail) {
const clicked = detail.event.target as HTMLIonSegmentButtonElement;
const buttons = this.getButtons();
@ -176,7 +193,7 @@ export class Segment implements ComponentInterface {
// If the gesture began on the clicked button with the indicator
// then we should activate the indicator
if (this.value === clicked.value) {
this.activated = true;
this.setActivated(true);
}
}