mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-24 08:50:34 +01:00
fix(ButtonGroup/FormGroup): pass default sizes to children (#1875)
This commit is contained in:
@@ -72,8 +72,12 @@ export function useInjectButtonGroup ({ ui, props }: { ui: any, props: any }) {
|
||||
onUnmounted(() => {
|
||||
groupContext?.value.unregister(instance)
|
||||
})
|
||||
|
||||
return {
|
||||
size: computed(() => groupContext?.value.size || props.size),
|
||||
size: computed(() => {
|
||||
if (!groupContext?.value) return props.size
|
||||
return groupContext?.value.size ?? ui.value.default.size
|
||||
}),
|
||||
rounded: computed(() => {
|
||||
if (!groupContext || positionInGroup.value === -1) return ui.value.rounded
|
||||
if (groupContext.value.children.length === 1) return groupContext.value.ui.rounded
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { inject, ref, computed } from 'vue'
|
||||
import { type UseEventBusReturn, useDebounceFn } from '@vueuse/core'
|
||||
import type { FormEvent, FormEventType, InjectedFormGroupValue } from '../types/form'
|
||||
import { mergeConfig } from '../utils'
|
||||
// @ts-expect-error
|
||||
import appConfig from '#build/app.config'
|
||||
import { formGroup } from '#ui/ui.config'
|
||||
|
||||
type InputProps = {
|
||||
id?: string
|
||||
@@ -11,6 +15,9 @@ type InputProps = {
|
||||
legend?: string | null
|
||||
}
|
||||
|
||||
|
||||
const formGroupConfig = mergeConfig<typeof formGroup>(appConfig.ui.strategy, appConfig.ui.formGroup, formGroup)
|
||||
|
||||
export const useFormGroup = (inputProps?: InputProps, config?: any) => {
|
||||
const formBus = inject<UseEventBusReturn<FormEvent, string> | undefined>('form-events', undefined)
|
||||
const formGroup = inject<InjectedFormGroupValue | undefined>('form-group', undefined)
|
||||
@@ -55,7 +62,7 @@ export const useFormGroup = (inputProps?: InputProps, config?: any) => {
|
||||
name: computed(() => inputProps?.name ?? formGroup?.name.value),
|
||||
size: computed(() => {
|
||||
const formGroupSize = config.size[formGroup?.size.value as string] ? formGroup?.size.value : null
|
||||
return inputProps?.size ?? formGroupSize ?? config?.default?.size
|
||||
return inputProps?.size ?? formGroupSize ?? formGroupConfig?.default?.size
|
||||
}),
|
||||
color: computed(() => formGroup?.error?.value ? 'red' : inputProps?.color),
|
||||
emitFormBlur,
|
||||
|
||||
Reference in New Issue
Block a user