-
-
Notifications
You must be signed in to change notification settings - Fork 776
feat: support per-handle disabled for Range slider #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EmilyyyLiu
wants to merge
23
commits into
react-component:master
Choose a base branch
from
EmilyyyLiu:feat/disabled-handle-array
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0667d6f
feat: add support for disabling specific slider handles and update st…
52c7208
feat: add onDisabledChange callback to sync disabled handles in edita…
5303584
docs: update README and example for disabled array feature
15e473f
docs: update README and examples to clarify disabled handle functiona…
204809d
feat: implement boundary constraints for disabled slider handles
a4c1c18
test: add test coverage
ed2438b
Update src/Slider.tsx
EmilyyyLiu 4e23930
Update src/Slider.tsx
EmilyyyLiu eee70b9
test: add coverage tests for pushable with disabled handles
zombieJ ea5b72e
refactor: simplify disabled handle implementation
9584ac3
fix: enforce required isHandleDisabled parameter in useDrag and useOf…
cda5aeb
refactor: make isHandleDisabled required in context
7fae517
fix: add missing isHandleDisabled default value in context
cf5819c
refactor: optimize disabled handle implementation based on review fee…
fbb2822
refactor: extract useDisabled hook to unify disabled handling
bc3a910
refactor: optimize disabled handle boundary calculation
cb346c4
Update docs/examples/disabled-handle.tsx
EmilyyyLiu 672a8ab
refactor: use Array.some instead of for loop in hasDisabledHandle
f94b6b1
Update src/Slider.tsx
EmilyyyLiu 866486b
fix: add boundary validation for click-to-move when handles are locked
98901c8
refactor: simplify useDisabled hook by removing isHandleDisabled
93f1734
refactor: streamline useDisabled hook by removing mergedValue parameter
9f9f44d
fix: ensure disabled state is correctly evaluated when rawValue is empty
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| title: Disabled Handle | ||
| title.zh-CN: 禁用特定滑块 | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|
|
||
| <code src="../examples/disabled-handle.tsx"></code> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* eslint react/no-multi-comp: 0, no-console: 0 */ | ||
| import Slider from '@rc-component/slider'; | ||
| import React, { useState } from 'react'; | ||
| import '../../assets/index.less'; | ||
|
|
||
| const style: React.CSSProperties = { | ||
| width: 400, | ||
| margin: 50, | ||
| }; | ||
|
|
||
| const defaultValue = [0, 30, 60, 100]; | ||
| const BasicDisabledHandle = () => { | ||
| const [disabled, setDisabled] = useState([true]); | ||
|
|
||
| return ( | ||
| <div> | ||
| <Slider range={{ draggableTrack: true }} defaultValue={defaultValue} disabled={disabled} /> | ||
| Slider disabled {JSON.stringify(disabled)} | ||
| <div style={{ marginTop: 16 }}> | ||
| {defaultValue.map((_, index) => ( | ||
| <label key={index} style={{ marginRight: 16 }}> | ||
| <input | ||
| type="checkbox" | ||
| checked={!!disabled[index]} | ||
| onChange={() => { | ||
| const newDisabled = [...disabled]; | ||
| newDisabled[index] = !newDisabled[index]; | ||
| setDisabled(newDisabled); | ||
| }} | ||
| /> | ||
| Handle {index + 1} {disabled[index] ? 'Disabled' : 'Enabled'} | ||
| </label> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const DisabledHandleAsBoundary = () => { | ||
| const [value, setValue] = useState<number[]>([10, 50, 90]); | ||
|
|
||
| return ( | ||
| <div> | ||
| <Slider | ||
| range | ||
| step={10} | ||
| value={value} | ||
| onChange={(v) => Array.isArray(v) && setValue(v)} | ||
| disabled={[false, true, false]} | ||
| /> | ||
| <p style={{ marginTop: 8, color: '#999' }}> | ||
| Middle handle (50) is disabled and acts as a boundary. First handle cannot go beyond 50, | ||
| third handle cannot go below 50. Disabled handle has gray border and not-allowed cursor. | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const PushableWithDisabledHandle = () => { | ||
| const [value, setValue] = useState<number[]>([20, 40, 60, 80]); | ||
|
|
||
| return ( | ||
| <div> | ||
| <Slider | ||
| range | ||
| value={value} | ||
| onChange={(v) => setValue(v as number[])} | ||
| disabled={[false, true, false, false]} | ||
| pushable={10} | ||
| /> | ||
| <p style={{ marginTop: 8, color: '#999' }}> | ||
| Second handle (40) is disabled. Drag the first handle toward it or push the last two handles | ||
| together: enabled handles keep at least 10 apart without crossing the disabled handle. | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const SingleSlider = () => { | ||
| const [value1, setValue1] = useState(30); | ||
| const [value2, setValue2] = useState(30); | ||
|
|
||
| return ( | ||
| <div> | ||
| <Slider value={value1} onChange={(v) => setValue1(v as number)} disabled /> | ||
| <br /> | ||
| <Slider value={value2} onChange={(v) => setValue2(v as number)} disabled={false} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| // Editable mode with disabled handles - editable is disabled when any handle is disabled | ||
| const EditableWithDisabled = () => { | ||
| const [value, setValue] = useState<number[]>([0, 30, 100]); | ||
| const [disabled, setDisabled] = useState<boolean[]>([true, false, false]); | ||
|
|
||
| const hasDisabled = disabled.some((d) => d); | ||
|
|
||
| return ( | ||
| <div> | ||
| <Slider | ||
| range={{ | ||
| editable: true, | ||
| minCount: 2, | ||
| maxCount: 5, | ||
| }} | ||
| value={value} | ||
| onChange={(v) => setValue(v as number[])} | ||
| disabled={disabled} | ||
| /> | ||
| <p style={{ marginTop: 8, color: hasDisabled ? '#f5222d' : '#52c41a' }}> | ||
| {hasDisabled | ||
| ? 'Editable mode is DISABLED because at least one handle is disabled. Clicking track will move nearest enabled handle.' | ||
| : 'Editable mode is ENABLED. Click track to add handles, drag to edge to delete.'} | ||
| </p> | ||
| <div style={{ marginTop: 16 }}> | ||
| {value.map((val, index) => ( | ||
| <label key={index} style={{ marginRight: 16 }}> | ||
| <input | ||
| type="checkbox" | ||
| checked={!!disabled[index]} | ||
| onChange={() => { | ||
| const newDisabled = [...disabled]; | ||
| newDisabled[index] = !newDisabled[index]; | ||
| setDisabled(newDisabled); | ||
| }} | ||
| /> | ||
| Handle {index + 1} ({val}) {disabled[index] ? 'Disabled' : 'Enabled'} | ||
| </label> | ||
| ))} | ||
| </div> | ||
| <p style={{ marginTop: 8, color: '#999', fontSize: 12 }}> | ||
| Try: Toggle checkboxes to enable/disable handles. When any handle is disabled, you cannot | ||
| add or remove handles. When all handles are enabled, editable mode works normally. | ||
| </p> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default () => ( | ||
| <div> | ||
| <div> | ||
| single handle disabled | ||
| <SingleSlider /> | ||
| </div> | ||
| <div style={style}> | ||
| <h3>Disabled Handle + Draggable Track</h3> | ||
| <p> | ||
| Toggle checkboxes to disable/enable specific handles. Drag the track area to move the range. | ||
| </p> | ||
| <BasicDisabledHandle /> | ||
| </div> | ||
|
|
||
| <div style={style}> | ||
| <h3>Disabled Handle as Boundary</h3> | ||
| <DisabledHandleAsBoundary /> | ||
| </div> | ||
|
|
||
| <div style={style}> | ||
| <h3>Disabled Handle + Pushable</h3> | ||
| <PushableWithDisabledHandle /> | ||
| </div> | ||
|
|
||
| <div style={style}> | ||
| <h3>Editable + Disabled (Editable Disabled When Any Handle Disabled)</h3> | ||
| <EditableWithDisabled /> | ||
| </div> | ||
| </div> | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.