BlazorSliders
BlazorSliders copied to clipboard
Add Disabled property to BlazorSliders to prevent user interaction
This PR adds a new Disabled property to both VerticalSliderPanel and HorizontalSliderPanel components that prevents user interaction with the slider when set to true. This addresses scenarios where you need to prevent a page from being "made visible" when its initial start width is 0.
Key Features
-
Disabledparameter (bool, default:false) available on both slider components - Visual feedback - disabled sliders show reduced opacity (0.5) and a "not-allowed" cursor
- Complete interaction blocking - all mouse and touch events are prevented when disabled
- Runtime toggling - the disabled state can be changed dynamically during the component lifecycle
- Backwards compatible - only adds one optional boolean parameter
Technical Implementation
The implementation includes:
-
C# Components: Added
Disabledparameter toSliderPanelBaseand state management in both slider components -
JavaScript Integration: Enhanced
Sliders.jsto respect disabled state and apply appropriate styling - Dynamic Updates: Implemented proper lifecycle methods to handle runtime disabled state changes
-
Visual Styling: Applied CSS styling (
opacity,cursor,pointer-events) for disabled state
Usage
<!-- Static disabled state -->
<VerticalSliderPanel Disabled="true" LeftPanelStartingWidth="400">
<LeftChildContent>Left content</LeftChildContent>
<RightChildContent>Right content</RightChildContent>
</VerticalSliderPanel>
<!-- Dynamic disabled state -->
<VerticalSliderPanel Disabled="@isDisabled" LeftPanelStartingWidth="400">
<LeftChildContent>Left content</LeftChildContent>
<RightChildContent>Right content</RightChildContent>
</VerticalSliderPanel>
Demo
The implementation includes a working demo that shows the toggle functionality:
Enabled State:
Disabled State:
Fixes #3.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.