js-kompo-utils 1.0.22 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,37 @@
1
1
  <template>
2
2
  <vl-form-field v-bind="$_wrapperAttributes">
3
- <vlTaggableInput
4
- v-click-out="blur"
5
- v-bind="$_taggableInputAttributes"
6
- v-on="$_taggableInputEvents"
7
- ref="taggableInput">
8
- <template v-slot:prepend v-if="$_icon">
9
- <div v-bind="prependIcon" />
10
- </template>
11
- <input
12
- class="vlFormControl"
13
- v-bind="$_attributes"
14
- v-on="$_events"
15
- v-model="inputValue"
16
- @keydown.enter.prevent="() => {}"
17
- ref="input"
18
- type="search"
19
- autocomplete="off"
20
- />
21
- <template v-slot:append v-if="appendIcon && !$_readOnly">
22
- <div v-html="appendIcon"/>
23
- </template>
24
- </vlTaggableInput>
3
+ <div :style="useNativeMobile ? { position: 'relative' } : null">
4
+ <vlTaggableInput
5
+ v-click-out="blur"
6
+ v-bind="$_taggableInputAttributes"
7
+ v-on="$_taggableInputEvents"
8
+ ref="taggableInput">
9
+ <template v-slot:prepend v-if="$_icon">
10
+ <div v-bind="prependIcon" />
11
+ </template>
12
+ <input
13
+ class="vlFormControl"
14
+ v-bind="$_attributes"
15
+ v-on="$_events"
16
+ v-model="inputValue"
17
+ @keydown.enter.prevent="() => {}"
18
+ ref="input"
19
+ type="search"
20
+ autocomplete="off"
21
+ />
22
+ <template v-slot:append v-if="appendIcon && !$_readOnly">
23
+ <div v-html="appendIcon"/>
24
+ </template>
25
+ </vlTaggableInput>
26
+ <select v-if="useNativeMobile"
27
+ class="vlNativeSelect"
28
+ :value="nativeValue"
29
+ @change="onNativeChange"
30
+ :style="nativeSelectStyle">
31
+ <option value="">{{ nativePlaceholder }}</option>
32
+ <option v-for="opt in options" :key="opt.value" :value="opt.value">{{ nativeLabel(opt) }}</option>
33
+ </select>
34
+ </div>
25
35
  <div class="vlOptions vlOptionsTeleported"
26
36
  :key="optionsKey"
27
37
  ref="selectOptions"
@@ -60,6 +70,7 @@ export default {
60
70
  return {
61
71
  flipUp: false,
62
72
  panelStyle: null,
73
+ isTouchDevice: false,
63
74
  }
64
75
  },
65
76
  computed: {
@@ -73,6 +84,28 @@ export default {
73
84
  if (!this.isFocused || !this.panelStyle) return { display: 'none' }
74
85
  return this.panelStyle
75
86
  },
87
+ useNativeMobile() {
88
+ if (this.$_config('disableNativeMobile')) return false
89
+ return this.isTouchDevice && !this.$_multiple && !this.ajaxOptions
90
+ },
91
+ nativeValue() {
92
+ return this.$_value && this.$_value.length ? this.$_value[0].value : ''
93
+ },
94
+ nativePlaceholder() {
95
+ return this.$_config('placeholder') || ''
96
+ },
97
+ nativeSelectStyle() {
98
+ return {
99
+ position: 'absolute',
100
+ top: 0, left: 0, right: 0, bottom: 0,
101
+ width: '100%', height: '100%',
102
+ opacity: 0,
103
+ appearance: 'none',
104
+ border: 0,
105
+ background: 'transparent',
106
+ zIndex: 2,
107
+ }
108
+ },
76
109
  },
77
110
  watch: {
78
111
  isFocused(focused) {
@@ -91,12 +124,27 @@ export default {
91
124
  },
92
125
  mounted() {
93
126
  this.teleportOptions()
127
+ if (typeof window !== 'undefined' && window.matchMedia) {
128
+ this.isTouchDevice = window.matchMedia('(pointer: coarse)').matches
129
+ }
94
130
  },
95
131
  beforeDestroy() {
96
132
  this.cleanupOptions()
97
133
  this.detachListeners()
98
134
  },
99
135
  methods: {
136
+ onNativeChange(e) {
137
+ const v = e.target.value
138
+ if (v === '') return
139
+ const opt = this.options.find(o => String(o.value) === String(v))
140
+ if (opt) this.select(opt)
141
+ },
142
+ nativeLabel(opt) {
143
+ const l = opt.label
144
+ if (typeof l === 'string') return l
145
+ if (l && typeof l === 'object') return l.label || l.text || l.search || ''
146
+ return String(opt.value ?? '')
147
+ },
100
148
  teleportOptions() {
101
149
  const opts = this.$refs.selectOptions
102
150
  if (opts && opts.parentNode !== document.body) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-kompo-utils",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "",
5
5
  "main": "app.js",
6
6
  "scripts": {