Skip to content

Commit d89d0d2

Browse files
vaebekagol
authored andcommitted
fix(input-number): 组件 props size 如果在表单内应该跟随表单变化。
1 parent 6956bd0 commit d89d0d2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/devui-vue/devui/input-number/src/input-number-types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export const inputNumberProps = {
2323
default: -Infinity,
2424
},
2525
size: {
26-
type: String as PropType<ISize>,
27-
default: 'md',
26+
type: String as PropType<ISize>
2827
},
2928
modelValue: {
3029
type: Number,

packages/devui-vue/devui/input-number/src/use-input-number.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import { computed, reactive, toRefs, watch, ref } from 'vue';
1+
import { computed, reactive, toRefs, watch, ref, inject } from 'vue';
22
import type { SetupContext, Ref, CSSProperties } from 'vue';
33
import { InputNumberProps, UseEvent, UseRender, IState, UseExpose } from './input-number-types';
44
import { useNamespace } from '../../shared/hooks/use-namespace';
55
import { isNumber, isUndefined } from '../../shared/utils';
6+
import { FORM_TOKEN } from '../../form';
67

78
const ns = useNamespace('input-number');
89

910
export function useRender(props: InputNumberProps, ctx: SetupContext): UseRender {
11+
const formContext = inject(FORM_TOKEN, undefined);
1012
const { style, class: customClass, ...otherAttrs } = ctx.attrs;
1113
const customStyle = { style: style as CSSProperties };
1214

15+
const inputNumberSize = computed(() => props.size || formContext?.size || 'md');
16+
1317
const wrapClass = computed(() => [
1418
{
1519
[ns.b()]: true,
16-
[ns.m(props.size)]: true,
20+
[ns.m(inputNumberSize.value)]: true,
1721
},
1822
customClass,
1923
]);
@@ -179,7 +183,7 @@ export function useEvent(props: InputNumberProps, ctx: SetupContext, inputRef: R
179183
(val) => {
180184
state.currentValue = correctValue(val);
181185
},
182-
{ immediate: true },
186+
{ immediate: true }
183187
);
184188

185189
const onInput = (event: Event) => {

0 commit comments

Comments
 (0)