Skip to content

Commit 74f2380

Browse files
committed
Remove currentValue exported ref
1 parent a70da54 commit 74f2380

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

demo/lib/vue-picker.esm.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ function useDropdownAsChild () {
142142
/**
143143
* @typedef {object} OptionsHookResult
144144
* @property {import('vue').Ref<VuePickerOption>} current
145-
* @property {import('vue').Ref<string>} currentValue
146145
* @property {OnSelectFunc} onSelect
147-
* @property {RegisterOptionFunc} registerOption
148146
* @property {SelectByValueFunc} selectByValue
149147
* @property {Function} selectNext
150148
* @property {Function} selectPrev
@@ -159,8 +157,6 @@ function useDropdownAsChild () {
159157
function useOptions (optsContRef) {
160158
/** @type {import('vue').Ref<VuePickerOption>} */
161159
var current = ref(null);
162-
/** @type {import('vue').Ref<string} */
163-
var currentValue = ref(null);
164160
/** @type {Object<string,VuePickerOption>} */
165161
var _options = {};
166162
/** @type {NodeListOf<HTMLButtonElement>} */
@@ -179,15 +175,13 @@ function useOptions (optsContRef) {
179175

180176
if (!opt) {
181177
current.value = null;
182-
currentValue.value = null;
183178
_currentIdx = -1;
184179
_onSelect(null);
185180
return
186181
}
187182

188183
opt.setIsSelected(true);
189184
current.value = opt;
190-
currentValue.value = opt.value;
191185
_currentIdx = _getNodeIdx(opt.value);
192186
_onSelect(opt.value);
193187
};
@@ -241,7 +235,6 @@ function useOptions (optsContRef) {
241235

242236
return {
243237
current: current,
244-
currentValue: currentValue,
245238
onSelect: function (cb) {
246239
if ( cb === void 0 ) cb = function () { };
247240
_onSelect = cb; },
@@ -413,20 +406,24 @@ var script$1 = {
413406
});
414407

415408
var _emitModelValue = function (val) {
416-
if ( val === void 0 ) val = options.currentValue.value;
409+
if ( val === void 0 ) val = _curOptVal();
417410

418411
if (typeof val !== 'string') { return }
419412
emit('update:modelValue', val);
420413
};
421414

415+
var _curOptVal = function () {
416+
return options.current.value && options.current.value.value
417+
};
418+
422419
return {
423420
openerRef: openerRef,
424421
dropdownRef: dropdownRef,
425422
dropdownIsShown: dropdown.isShown,
426423
dropdownClickOutRef: dropdown.clickOutRef,
427424
dropdownToggle: function () { return dropdown.toggle(); },
428425
curOpt: options.current,
429-
curOptVal: options.currentValue,
426+
curOptVal: computed(function () { return _curOptVal(); }),
430427
openerTxt: computed(function () {
431428
if (!modelValue.value && placeholder.value) { return placeholder.value }
432429
return options.current.value && options.current.value.optTxt
@@ -462,7 +459,11 @@ function render$1(_ctx, _cache, $props, $setup, $data, $options) {
462459
disabled: $props.isDisabled
463460
}, [
464461
renderSlot(_ctx.$slots, "opener", {
465-
opener: { value: $setup.curOptVal, text: $setup.openerTxt, opt: $setup.curOpt }
462+
opener: {
463+
value: $setup.curOpt && $setup.curOpt.value,
464+
text: $setup.openerTxt,
465+
opt: $setup.curOpt,
466+
}
466467
}, function () { return [
467468
createVNode("span", {
468469
class: "vue-picker__opener-txt",

src/components/VuePicker.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
>
1818
<slot
1919
name="opener"
20-
:opener="{ value: curOptVal, text: openerTxt, opt: curOpt }"
20+
:opener="{
21+
value: curOpt && curOpt.value,
22+
text: openerTxt,
23+
opt: curOpt,
24+
}"
2125
>
2226
<span class="vue-picker__opener-txt" v-html="openerHtml" />
2327
</slot>
@@ -102,19 +106,23 @@ export default {
102106
keyboard.unlisten(document)
103107
})
104108
105-
const _emitModelValue = (val = options.currentValue.value) => {
109+
const _emitModelValue = (val = _curOptVal()) => {
106110
if (typeof val !== 'string') return
107111
emit('update:modelValue', val)
108112
}
109113
114+
const _curOptVal = () => {
115+
return options.current.value && options.current.value.value
116+
}
117+
110118
return {
111119
openerRef,
112120
dropdownRef,
113121
dropdownIsShown: dropdown.isShown,
114122
dropdownClickOutRef: dropdown.clickOutRef,
115123
dropdownToggle: () => dropdown.toggle(),
116124
curOpt: options.current,
117-
curOptVal: options.currentValue,
125+
curOptVal: computed(() => _curOptVal()),
118126
openerTxt: computed(() => {
119127
if (!modelValue.value && placeholder.value) return placeholder.value
120128
return options.current.value && options.current.value.optTxt

src/composables/useOptions.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ import { inject, nextTick, onMounted, onUpdated, provide, ref } from 'vue'
3434
/**
3535
* @typedef {object} OptionsHookResult
3636
* @property {import('vue').Ref<VuePickerOption>} current
37-
* @property {import('vue').Ref<string>} currentValue
3837
* @property {OnSelectFunc} onSelect
39-
* @property {RegisterOptionFunc} registerOption
4038
* @property {SelectByValueFunc} selectByValue
4139
* @property {Function} selectNext
4240
* @property {Function} selectPrev
@@ -51,8 +49,6 @@ import { inject, nextTick, onMounted, onUpdated, provide, ref } from 'vue'
5149
export function useOptions (optsContRef) {
5250
/** @type {import('vue').Ref<VuePickerOption>} */
5351
const current = ref(null)
54-
/** @type {import('vue').Ref<string} */
55-
const currentValue = ref(null)
5652
/** @type {Object<string,VuePickerOption>} */
5753
const _options = {}
5854
/** @type {NodeListOf<HTMLButtonElement>} */
@@ -69,15 +65,13 @@ export function useOptions (optsContRef) {
6965

7066
if (!opt) {
7167
current.value = null
72-
currentValue.value = null
7368
_currentIdx = -1
7469
_onSelect(null)
7570
return
7671
}
7772

7873
opt.setIsSelected(true)
7974
current.value = opt
80-
currentValue.value = opt.value
8175
_currentIdx = _getNodeIdx(opt.value)
8276
_onSelect(opt.value)
8377
}
@@ -128,7 +122,6 @@ export function useOptions (optsContRef) {
128122

129123
return {
130124
current,
131-
currentValue,
132125
onSelect: (cb = () => { }) => { _onSelect = cb },
133126
selectByValue,
134127
selectNext,

0 commit comments

Comments
 (0)