BlazorSliders icon indicating copy to clipboard operation
BlazorSliders copied to clipboard

Add Disabled property to BlazorSliders to prevent user interaction

Open Copilot opened this issue 8 months ago • 3 comments

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

  • Disabled parameter (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:

  1. C# Components: Added Disabled parameter to SliderPanelBase and state management in both slider components
  2. JavaScript Integration: Enhanced Sliders.js to respect disabled state and apply appropriate styling
  3. Dynamic Updates: Implemented proper lifecycle methods to handle runtime disabled state changes
  4. 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: Enabled Slider

Disabled State: Disabled Slider

Fixes #3.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Aug 09 '25 18:08 Copilot