|
1 | 1 | <template> |
2 | | - <div class="dp__overlay" :id="gridId" :class="dpOverlayClass" role="dialog"> |
| 2 | + <div class="dp__overlay" ref="gridWrapRef" :class="dpOverlayClass" role="dialog"> |
3 | 3 | <div class="dp__overlay_container" role="grid"> |
4 | 4 | <div class="dp__selection_grid_header"><slot name="header"></slot></div> |
5 | 5 | <div class="dp__overlay_row" v-for="(row, i) in mappedItems" :key="getKey(i)" role="row"> |
|
11 | 11 | @click="onClick(col.value)" |
12 | 12 | :aria-selected="col.value === modelValue && !disabledValues.includes(col.value)" |
13 | 13 | :aria-disabled="col.className.dp__overlay_cell_disabled" |
14 | | - :id=" |
15 | | - col.value === modelValue && !disabledValues.includes(col.value) ? `selection-active${uid}` : '' |
16 | | - " |
| 14 | + :ref="col.value === modelValue && !disabledValues.includes(col.value) ? `selectionActiveRef` : ''" |
17 | 15 | > |
18 | 16 | <div :class="col.className"> |
19 | 17 | <slot v-if="$slots.item" name="item" :item="col" /> |
|
38 | 36 | import { computed, onMounted, PropType, ref } from 'vue'; |
39 | 37 |
|
40 | 38 | import { IDefaultSelect, DynamicClass } from '../interfaces'; |
41 | | - import { getKey } from '../utils/util'; |
| 39 | + import { getKey, unrefElement } from '../utils/util'; |
42 | 40 |
|
43 | 41 | const emit = defineEmits(['update:modelValue', 'selected', 'toggle']); |
44 | 42 |
|
45 | 43 | const props = defineProps({ |
46 | | - uid: { type: [String, Number] as PropType<string | number>, default: '' }, |
47 | 44 | items: { type: Array as PropType<IDefaultSelect[][]>, default: () => [] }, |
48 | 45 | modelValue: { type: [String, Number] as PropType<string | number>, default: null }, |
49 | | - gridId: { type: String as PropType<string>, default: 'dp__overlay' }, |
50 | 46 | disabledValues: { type: Array as PropType<number[]>, default: () => [] }, |
51 | 47 | minValue: { type: [Number, String] as PropType<number | string>, default: null }, |
52 | 48 | maxValue: { type: [Number, String] as PropType<number | string>, default: null }, |
53 | 49 | }); |
54 | 50 |
|
55 | 51 | const scrollable = ref(false); |
| 52 | + const selectionActiveRef = ref(null); |
| 53 | + const gridWrapRef = ref(null); |
56 | 54 |
|
57 | 55 | /** |
58 | 56 | * On mounted hook, set the scroll position, if any to a selected value when opening overlay |
59 | 57 | */ |
60 | 58 | onMounted(() => { |
61 | 59 | setScrollPosition(); |
62 | | - const elm = document.getElementById(props.gridId); |
| 60 | + const elm = unrefElement(gridWrapRef); |
63 | 61 | if (elm) { |
64 | 62 | scrollable.value = elm.clientHeight < elm.scrollHeight; |
65 | 63 | } |
|
124 | 122 | * Set scroll position in overlay based on active selection |
125 | 123 | */ |
126 | 124 | const setScrollPosition = (): void => { |
127 | | - const el = document.getElementById(`selection-active${props.uid}`); |
| 125 | + const el = unrefElement(selectionActiveRef); |
128 | 126 | if (el) { |
129 | | - const parent = document.getElementById(props.gridId); |
| 127 | + const parent = unrefElement(gridWrapRef); |
130 | 128 | if (parent) { |
131 | 129 | parent.scrollTop = |
132 | 130 | el.offsetTop - |
|
0 commit comments