|
10 | 10 | let { value, disabled = false, onvalue }: Props = $props();
|
11 | 11 |
|
12 | 12 | function setValue(event: MouseEvent) {
|
13 |
| - let element = event.target as HTMLElement; |
14 |
| - let position = element.dataset.position as ReferencePoint; |
15 |
| - onvalue?.(position); |
| 13 | + const element = event.target as HTMLDivElement; |
| 14 | + const button = element.parentElement; |
| 15 | + if (button) { |
| 16 | + let position = button.dataset.position! as ReferencePoint; |
| 17 | + onvalue?.(position); |
| 18 | + } |
16 | 19 | }
|
17 | 20 | </script>
|
18 | 21 |
|
19 |
| -<div class="reference-point-input" class:disabled> |
20 |
| - <button onclick={setValue} data-position="TopLeft" class="row-1 col-1" class:active={value === "TopLeft"} tabindex="-1" {disabled}><div></div></button> |
21 |
| - <button onclick={setValue} data-position="TopCenter" class="row-1 col-2" class:active={value === "TopCenter"} tabindex="-1" {disabled}><div></div></button> |
22 |
| - <button onclick={setValue} data-position="TopRight" class="row-1 col-3" class:active={value === "TopRight"} tabindex="-1" {disabled}><div></div></button> |
23 |
| - <button onclick={setValue} data-position="CenterLeft" class="row-2 col-1" class:active={value === "CenterLeft"} tabindex="-1" {disabled}><div></div></button> |
24 |
| - <button onclick={setValue} data-position="Center" class="row-2 col-2" class:active={value === "Center"} tabindex="-1" {disabled}><div></div></button> |
25 |
| - <button onclick={setValue} data-position="CenterRight" class="row-2 col-3" class:active={value === "CenterRight"} tabindex="-1" {disabled}><div></div></button> |
26 |
| - <button onclick={setValue} data-position="BottomLeft" class="row-3 col-1" class:active={value === "BottomLeft"} tabindex="-1" {disabled}><div></div></button> |
27 |
| - <button onclick={setValue} data-position="BottomCenter" class="row-3 col-2" class:active={value === "BottomCenter"} tabindex="-1" {disabled}><div></div></button> |
28 |
| - <button onclick={setValue} data-position="BottomRight" class="row-3 col-3" class:active={value === "BottomRight"} tabindex="-1" {disabled}><div></div></button> |
| 22 | +<div class="reference-point-input" class:disabled onclick={setValue}> |
| 23 | + <button data-position="TopLeft" class="row-1 col-1" class:active={value === "TopLeft"} tabindex="-1" {disabled}><div></div></button> |
| 24 | + <button data-position="TopCenter" class="row-1 col-2" class:active={value === "TopCenter"} tabindex="-1" {disabled}><div></div></button> |
| 25 | + <button data-position="TopRight" class="row-1 col-3" class:active={value === "TopRight"} tabindex="-1" {disabled}><div></div></button> |
| 26 | + <button data-position="CenterLeft" class="row-2 col-1" class:active={value === "CenterLeft"} tabindex="-1" {disabled}><div></div></button> |
| 27 | + <button data-position="Center" class="row-2 col-2" class:active={value === "Center"} tabindex="-1" {disabled}><div></div></button> |
| 28 | + <button data-position="CenterRight" class="row-2 col-3" class:active={value === "CenterRight"} tabindex="-1" {disabled}><div></div></button> |
| 29 | + <button data-position="BottomLeft" class="row-3 col-1" class:active={value === "BottomLeft"} tabindex="-1" {disabled}><div></div></button> |
| 30 | + <button data-position="BottomCenter" class="row-3 col-2" class:active={value === "BottomCenter"} tabindex="-1" {disabled}><div></div></button> |
| 31 | + <button data-position="BottomRight" class="row-3 col-3" class:active={value === "BottomRight"} tabindex="-1" {disabled}><div></div></button> |
29 | 32 | </div>
|
30 | 33 |
|
31 | 34 | <style lang="scss" global>
|
|
0 commit comments