Refactor InteractiveChip component to improve touch event handling

This commit updates the InteractiveChip component by refining touch event handling for better user interaction on touch devices. The `HandleClick` method has been replaced with `HandleTouchStart`, which now toggles the `_isTouched` state and prevents event propagation. This change enhances the responsiveness of the component, ensuring a smoother experience for users on mobile devices while maintaining existing hover functionality for desktop users.
This commit is contained in:
2026-01-19 12:09:57 -05:00
parent 7679a458e0
commit 9ed9c93540
@@ -6,9 +6,8 @@
Class="@WrapperClass"
@onmouseenter="@(() => _isHovered = true)"
@onmouseleave="@(() => _isHovered = false)"
@ontouchstart="@(() => _isTouched = true)"
@ontouchend="@(() => { /* Prevent mouse events on touch */ })"
@onclick="@HandleClick">
@ontouchstart="@HandleTouchStart"
@ontouchend="@((e) => { e.PreventDefault(); })">
<MudChip T="string"
Size="@Size"
Color="@Color"
@@ -69,12 +68,10 @@
private bool _isHovered = false;
private bool _isTouched = false;
private void HandleClick(MouseEventArgs e)
{
// On touch devices, toggle controls on tap (for devices with both touch and mouse)
if (_isTouched)
private void HandleTouchStart(TouchEventArgs e)
{
_isTouched = !_isTouched;
}
e.StopPropagation();
StateHasChanged();
}
}