-
-
Notifications
You must be signed in to change notification settings - Fork 784
feat: add handle index on change events #1062
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,12 +72,12 @@ export interface SliderProps<ValueType = number | number[]> { | |
step?: number | null; | ||
value?: ValueType; | ||
defaultValue?: ValueType; | ||
onChange?: (value: ValueType) => void; | ||
onChange?: (value: ValueType, index: number) => void; | ||
/** @deprecated It's always better to use `onChange` instead */ | ||
onBeforeChange?: (value: ValueType) => void; | ||
/** @deprecated Use `onChangeComplete` instead */ | ||
onAfterChange?: (value: ValueType) => void; | ||
onChangeComplete?: (value: ValueType) => void; | ||
onChangeComplete?: (value: ValueType, index: number) => void; | ||
Comment on lines
+75
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain建议:考虑更新现有示例代码 从相关代码片段看,现有的示例代码(如 🏁 Script executed: #!/bin/bash
# 检查当前是否有使用新 index 参数的示例代码
# 在 docs 目录下搜索 onChange 或 onChangeComplete 的使用
echo "检查示例代码中的回调函数使用情况:"
rg -A 2 "onChange(.*\).* =>\s*{|onChangeComplete(.*\).* =>\s*{" docs/ Length of output: 462 🏁 Script executed: #!/bin/bash
# 重新检查 docs/examples 目录中是否有使用新 index 参数的回调
echo "查找 docs/examples 目录中 onChange 和 onChangeComplete 的调用:"
rg "onChange\s*=" -n docs/examples
rg "onChangeComplete\s*=" -n docs/examples Length of output: 5236 更新示例以演示 index 参数 现有示例(如
请按需更新以下文件:
🤖 Prompt for AI Agents (early access)
|
||
|
||
// Cross | ||
allowCross?: boolean; | ||
|
@@ -300,7 +300,7 @@ const Slider = React.forwardRef<SliderRef, SliderProps<number | number[]>>((prop | |
|
||
// Trigger event if needed | ||
if (onChange && !isEqual(cloneNextValues, rawValues, true)) { | ||
onChange(getTriggerValue(cloneNextValues)); | ||
onChange(getTriggerValue(cloneNextValues), draggingIndex); | ||
} | ||
|
||
// We set this later since it will re-render component immediately | ||
|
@@ -319,7 +319,7 @@ const Slider = React.forwardRef<SliderRef, SliderProps<number | number[]>>((prop | |
!onAfterChange, | ||
'[rc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead.', | ||
); | ||
onChangeComplete?.(finishValue); | ||
onChangeComplete?.(finishValue, draggingIndex); | ||
}); | ||
|
||
const onDelete = (index: number) => { | ||
|
@@ -406,7 +406,7 @@ const Slider = React.forwardRef<SliderRef, SliderProps<number | number[]>>((prop | |
!onAfterChange, | ||
'[rc-slider] `onAfterChange` is deprecated. Please use `onChangeComplete` instead.', | ||
); | ||
onChangeComplete?.(nextValue); | ||
onChangeComplete?.(nextValue, draggingIndex); | ||
} | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
更新了 onChange 回调函数签名,添加了 index 参数
在
SliderProps
接口中,onChange
回调函数签名现在包含了一个额外的index
参数,用于表示正在操作的滑块句柄的索引。这个改进使开发者能够根据特定句柄的索引执行计算或逻辑。请注意,这是一个破坏性变更,可能需要更新现有的使用此组件的代码。
建议在文档中明确说明这个变更,并更新示例代码以展示如何利用这个新参数。例如,在
docs/examples/multiple.tsx
和docs/examples/editable.tsx
中的示例可以更新为:🤖 Prompt for AI Agents (early access)