Skip to content
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

feat(n-slider): add on-dragstart on-dragend prop #5382

Merged
merged 4 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- `n-upload` adds `file-list-class` and `trigger-class` props.
- `n-dynamic-input` adds `input-class` and `tag-class` props.
- `n-dynamic-input` adds `item-class` prop.
- `n-slider` adds `on-dragstart` `on-dragend` prop, closes [#5365](https://github.com/tusen-ai/naive-ui/issues/5365).

## 2.35.0

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- `n-upload` 新增 `file-list-class` 和 `trigger-class` 属性
- `n-dynamic-input` 新增 `input-class` 和 `tag-class` 属性
- `n-dynamic-input` 新增 `item-class` 属性
- `n-slider` 新增 `on-dragstart` `on-dragend` 属性,关闭 [#5365](https://github.com/tusen-ai/naive-ui/issues/5365)

## 2.35.0

Expand Down
2 changes: 2 additions & 0 deletions src/slider/demos/enUS/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ custom-thumb.vue
| vertical | `boolean` | `false` | Whether to enable vertical mode. | |
| value | `number \| [number, number] \| null` | `undefined` | Value of the slider. | |
| on-update:value | `(value: number \| [number, number]) => void` | `undefined` | Callback on value update. | |
| on-dragstart | `() => void` | `undefined` | Start dragging the callback function. | |
| on-dragend | `() => void` | `undefined` | Drag the end of the callback function. | |
07akioni marked this conversation as resolved.
Show resolved Hide resolved

### Slider Slots

Expand Down
2 changes: 2 additions & 0 deletions src/slider/demos/zhCN/index.demo-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ keyboard-debug.vue
| vertical | `boolean` | `false` | 是否启用垂直模式 | |
| value | `number \| [number, number] \| null` | `undefined` | 值 | |
| on-update:value | `(value: number \| [number, number]) => void` | `undefined` | 值更新的回调 | |
| on-dragstart | `() => void` | `undefined` | 开始拖拽的回调函数 | |
| on-dragend | `() => void` | `undefined` | 拖拽结束的回调函数 | |
07akioni marked this conversation as resolved.
Show resolved Hide resolved

### Slider Slots

Expand Down
6 changes: 5 additions & 1 deletion src/slider/src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const sliderProps = {
>,
onUpdateValue: [Function, Array] as PropType<
MaybeArray<(value: number & number[]) => void>
>
>,
onDragstart: [Function] as PropType<() => void>,
onDragend: [Function] as PropType<() => void>
} as const

export type SliderProps = ExtractPublicPropTypes<typeof sliderProps>
Expand Down Expand Up @@ -466,6 +468,7 @@ export default defineComponent({
function startDragging (): void {
if (!draggingRef.value) {
draggingRef.value = true
if (props.onDragstart) call(props.onDragstart)
on('touchend', document, handleMouseUp)
on('mouseup', document, handleMouseUp)
on('touchmove', document, handleMouseMove)
Expand All @@ -475,6 +478,7 @@ export default defineComponent({
function stopDragging (): void {
if (draggingRef.value) {
draggingRef.value = false
if (props.onDragend) call(props.onDragend)
off('touchend', document, handleMouseUp)
off('mouseup', document, handleMouseUp)
off('touchmove', document, handleMouseMove)
Expand Down
Loading