Skip to content

Commit f225e01

Browse files
committed
feat: add start & end events to Knob
1 parent 9374fbe commit f225e01

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/components/Knob.vue

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const props = withDefaults(defineProps<{
1818
1919
const emit = defineEmits<{
2020
(e: 'update:modelValue', value: number): void
21+
(e: 'start'): void
22+
(e: 'end'): void
2123
}>()
2224
2325
function clamp(value: number) {
@@ -42,6 +44,8 @@ const percentage = computed(() => 100 / (props.max - props.min) * (clamp(props.m
4244
:fine-key="fineKey"
4345
:capture-mouse="captureMouse"
4446
@change="handleChange"
47+
@start="$emit('start')"
48+
@end="$emit('end')"
4549
>
4650
<slot
4751
:value="clamp(props.modelValue)"

src/components/MouseControl.vue

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const props = withDefaults(defineProps<{
1515
1616
const emits = defineEmits<{
1717
(e: 'change', delta: number): void
18+
(e: 'start'): void
19+
(e: 'end'): void
1820
}>()
1921
2022
const el = ref<null | HTMLElement>(null)
@@ -57,6 +59,8 @@ function handleMouseUp() {
5759
document.exitPointerLock()
5860
else
5961
document.removeEventListener('mousemove', handleMove, false)
62+
63+
emits('end')
6064
}
6165
6266
onMounted(() => {
@@ -70,6 +74,8 @@ onMounted(() => {
7074
el.value?.addEventListener('mousedown', (event) => {
7175
event.stopPropagation()
7276
event.preventDefault()
77+
emits('start')
78+
7379
if (props.captureMouse)
7480
el.value?.requestPointerLock()
7581
else

0 commit comments

Comments
 (0)