MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / checkButton

Method checkButton

core/src/components/segment/segment.tsx:317–354  ·  view source on GitHub ↗
(previous: HTMLIonSegmentButtonElement, current: HTMLIonSegmentButtonElement)

Source from the content-addressed store, hash-verified

315 }
316
317 private checkButton(previous: HTMLIonSegmentButtonElement, current: HTMLIonSegmentButtonElement) {
318 const previousIndicator = this.getIndicator(previous);
319 const currentIndicator = this.getIndicator(current);
320
321 if (previousIndicator === null || currentIndicator === null) {
322 return;
323 }
324
325 const previousClientRect = previousIndicator.getBoundingClientRect();
326 const currentClientRect = currentIndicator.getBoundingClientRect();
327
328 const widthDelta = previousClientRect.width / currentClientRect.width;
329 const xPosition = previousClientRect.left - currentClientRect.left;
330
331 // Scale the indicator width to match the previous indicator width
332 // and translate it on top of the previous indicator
333 const transform = `translate3d(${xPosition}px, 0, 0) scaleX(${widthDelta})`;
334
335 writeTask(() => {
336 // Remove the transition before positioning on top of the previous indicator
337 currentIndicator.classList.remove('segment-button-indicator-animated');
338 currentIndicator.style.setProperty('transform', transform);
339
340 // Force a repaint to ensure the transform happens
341 currentIndicator.getBoundingClientRect();
342
343 // Add the transition to move the indicator into place
344 currentIndicator.classList.add('segment-button-indicator-animated');
345
346 // Remove the transform to slide the indicator back to the button clicked
347 currentIndicator.style.setProperty('transform', '');
348
349 this.scrollActiveButtonIntoView(true);
350 });
351
352 this.value = current.value;
353 this.setCheckedClasses();
354 }
355
356 private setCheckedClasses() {
357 const buttons = this.getButtons();

Callers 5

valueChangedMethod · 0.95
setNextIndexMethod · 0.95
SegmentClass · 0.95
onKeyDownMethod · 0.95

Calls 4

getIndicatorMethod · 0.95
setCheckedClassesMethod · 0.95
addMethod · 0.45

Tested by

no test coverage detected