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:
@@ -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)
|
||||
private void HandleTouchStart(TouchEventArgs e)
|
||||
{
|
||||
// On touch devices, toggle controls on tap (for devices with both touch and mouse)
|
||||
if (_isTouched)
|
||||
{
|
||||
_isTouched = !_isTouched;
|
||||
}
|
||||
_isTouched = !_isTouched;
|
||||
e.StopPropagation();
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user