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"
|
Class="@WrapperClass"
|
||||||
@onmouseenter="@(() => _isHovered = true)"
|
@onmouseenter="@(() => _isHovered = true)"
|
||||||
@onmouseleave="@(() => _isHovered = false)"
|
@onmouseleave="@(() => _isHovered = false)"
|
||||||
@ontouchstart="@(() => _isTouched = true)"
|
@ontouchstart="@HandleTouchStart"
|
||||||
@ontouchend="@(() => { /* Prevent mouse events on touch */ })"
|
@ontouchend="@((e) => { e.PreventDefault(); })">
|
||||||
@onclick="@HandleClick">
|
|
||||||
<MudChip T="string"
|
<MudChip T="string"
|
||||||
Size="@Size"
|
Size="@Size"
|
||||||
Color="@Color"
|
Color="@Color"
|
||||||
@@ -69,12 +68,10 @@
|
|||||||
private bool _isHovered = false;
|
private bool _isHovered = false;
|
||||||
private bool _isTouched = 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