Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid removing focus from Segmented Control on embedded badge click #2400

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[value]="value?.id"
[scrollable]="disableChangeOnSwipe"
(ionChange)="onSegmentSelect($event.detail.value)"
(click)="preventWrapperClick($event)"
(click)="preventOutsideClick($event)"
>
<div *ngFor="let item of items" class="segment-btn-wrapper">
<ion-segment-button [value]="item.id">{{ item.text }}</ion-segment-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ export enum SegmentedControlMode {
export class SegmentedControlComponent {
constructor(private iconRegistryService: IconRegistryService) {}

preventWrapperClick(event: Event) {
/**
* Ensure that the click actually did originate from within the segment-button.
* We do not want to react to clicks on e.g. segment-btn-wrapper or badge.
*/
preventOutsideClick(event: TouchEvent) {
if (event.target instanceof HTMLElement) {
if (event.target.classList.contains('segment-btn-wrapper')) {
const targetIsInSegmentBtn = !!event.target.closest('ion-segment-button');
if (!targetIsInSegmentBtn) {
event.stopImmediatePropagation();
}
}
Expand Down