|
1 | | -import { computed, reactive, toRefs, watch, ref } from 'vue'; |
| 1 | +import { computed, reactive, toRefs, watch, ref, inject } from 'vue'; |
2 | 2 | import type { SetupContext, Ref, CSSProperties } from 'vue'; |
3 | 3 | import { InputNumberProps, UseEvent, UseRender, IState, UseExpose } from './input-number-types'; |
4 | 4 | import { useNamespace } from '../../shared/hooks/use-namespace'; |
5 | 5 | import { isNumber, isUndefined } from '../../shared/utils'; |
| 6 | +import { FORM_TOKEN } from '../../form'; |
6 | 7 |
|
7 | 8 | const ns = useNamespace('input-number'); |
8 | 9 |
|
9 | 10 | export function useRender(props: InputNumberProps, ctx: SetupContext): UseRender { |
| 11 | + const formContext = inject(FORM_TOKEN, undefined); |
10 | 12 | const { style, class: customClass, ...otherAttrs } = ctx.attrs; |
11 | 13 | const customStyle = { style: style as CSSProperties }; |
12 | 14 |
|
| 15 | + const inputNumberSize = computed(() => props.size || formContext?.size || 'md'); |
| 16 | + |
13 | 17 | const wrapClass = computed(() => [ |
14 | 18 | { |
15 | 19 | [ns.b()]: true, |
16 | | - [ns.m(props.size)]: true, |
| 20 | + [ns.m(inputNumberSize.value)]: true, |
17 | 21 | }, |
18 | 22 | customClass, |
19 | 23 | ]); |
@@ -179,7 +183,7 @@ export function useEvent(props: InputNumberProps, ctx: SetupContext, inputRef: R |
179 | 183 | (val) => { |
180 | 184 | state.currentValue = correctValue(val); |
181 | 185 | }, |
182 | | - { immediate: true }, |
| 186 | + { immediate: true } |
183 | 187 | ); |
184 | 188 |
|
185 | 189 | const onInput = (event: Event) => { |
|
0 commit comments