Skip to content

Commit 9baa28c

Browse files
committed
[Added] Dynamic inputmode props to component
1 parent a6006d3 commit 9baa28c

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

docs/.vuepress/components/BaseSelect.vue

+16-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
class="shadow-sm rounded-md text-base transition-all disabled:cursor-not-allowed disabled:border-gray-300 disabled:text-gray-300 focus:border-primary focus:ring focus:ring-offset-0 focus:ring-primary focus:ring-opacity-50ß"
66
@input="$emit('update:modelValue', $event.target.value)"
77
>
8-
<slot></slot>
8+
<slot>
9+
<option
10+
v-for="item in options"
11+
:key="item"
12+
:value="item"
13+
>
14+
{{ item }}
15+
</option>
16+
</slot>
917
</select>
1018
</template>
1119

@@ -14,14 +22,18 @@ export default {
1422
name: 'BaseInput',
1523
props: {
1624
modelValue: {
17-
default: undefined,
25+
default: undefined
1826
},
1927
label: {
2028
type: String,
21-
required: false,
29+
required: false
2230
},
31+
options: {
32+
type: Array,
33+
required: true
34+
}
2335
},
24-
emits: ['update:modelValue'],
36+
emits: ['update:modelValue']
2537
}
2638
</script>
2739

docs/.vuepress/components/PlayGround.vue

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@
117117
v-model.number="config.max"
118118
/>
119119
</div>
120+
<div class="mb-5 min-w-0 grid">
121+
<div class="mb-2 font-medium">Input mode</div>
122+
<BaseSelect
123+
:options="['decimal', 'numeric']"
124+
v-model="config.inputmode"
125+
/>
126+
</div>
120127
</div>
121128
<div class="mb-8">
122129
<Checkbox
@@ -150,6 +157,7 @@ export default {
150157
suffix: '',
151158
precision: 2,
152159
nullValue: '',
160+
inputmode: 'numeric',
153161
masked: false,
154162
reverseFill: false
155163
}

docs/guide/config.md

+8
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,11 @@ Value of `<input>` element is set to a default when no `value` present
101101
- Type: `string`
102102
- Default: `''`
103103
- Required: `false`
104+
105+
## inputmode
106+
107+
The [inputmode](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode) global attribute is an enumerated attribute that hints at the type of data that might be entered by the user while editing the element or its contents. This allows a browser to display an appropriate virtual keyboard.
108+
109+
- Type: `string`
110+
- Default: `numeric`
111+
- Required: `false`

src/component.vue

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export default defineComponent({
7777
suffix: {
7878
type: String,
7979
default: () => options.suffix
80+
},
81+
inputmode: {
82+
type: String,
83+
default: () => options.inputmode
8084
}
8185
},
8286
emits: ['update:model-value', 'input:model-value'],

src/directive.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export default {
77
beforeMount: (el: core.CustomInputElement, { value, modifiers }: DirectiveBinding, vnode: VNode) => {
88
el = core.getInputElement(el)
99
const options = Object.assign(core.cloneDeep(defaultOptions), value, modifiers)
10-
const { reverseFill, precision, decimal } = options
10+
const { reverseFill, precision, decimal, inputmode } = options
1111
el.options = options
12-
el.setAttribute('inputmode', 'numeric')
12+
el.setAttribute('inputmode', inputmode)
1313
if (reverseFill && el.value) {
1414
el.value = parseFloat(new NumberFormat({ ...options, reverseFill: false }).unformat(el.value)).toFixed(precision)
1515
if (vnode?.props?.value) {

src/options.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface Options {
33
suffix?: string
44
separator?: string
55
decimal?: string
6+
inputmode?: string
67
precision?: number
78
minimumFractionDigits?: number
89
prefill?: boolean
@@ -17,6 +18,7 @@ export default {
1718
suffix: '',
1819
separator: ',',
1920
decimal: '.',
21+
inputmode: 'numeric',
2022
precision: 2,
2123
minimumFractionDigits: null,
2224
prefill: true,

0 commit comments

Comments
 (0)