fix(components): [form] no margin when there is no label (#9940)

This commit is contained in:
Qiang
2022-09-27 22:54:00 +08:00
committed by GitHub
parent 7d1ecb6285
commit cc8b816bd9
4 changed files with 5 additions and 2 deletions

View File

@ -133,7 +133,7 @@ form/accessibility
| `label-position` | Position of label. If set to `'left'` or `'right'`, `label-width` prop is also required. | `'left' \| 'right' \| 'top'` | `'right'` |
| `label-width` | Width of label, e.g. `'50px'`. All its direct child form items will inherit this value. `auto` is supported. | `string \| number` | — |
| `label-suffix` | Suffix of the label. | `string` | — |
| `hide-required-asterisk` | Whether to hide required fields should have a red asterisk (star) beside their labels. | `boolean` | `false` |
| `hide-required-asterisk` | Whether to hide required fields should have a red asterisk (star) beside their labels. | `boolean` | `false` |
| `require-asterisk-position` | Position of asterisk. | `'left' \| 'right'` | `'left'` |
| `show-message` | Whether to show the error message. | `boolean` | `true` |
| `inline-message` | Whether to display the error message inline with the form item. | `boolean` | `false` |

View File

@ -377,6 +377,7 @@ const context: FormItemContext = reactive({
labelId,
inputIds,
isGroup,
hasLabel,
addInputId,
removeInputId,
resetField,

View File

@ -88,8 +88,9 @@ export default defineComponent({
const { isAutoWidth } = props
if (isAutoWidth) {
const autoLabelWidth = formContext?.autoLabelWidth
const hasLabel = formItemContext?.hasLabel
const style: CSSProperties = {}
if (autoLabelWidth && autoLabelWidth !== 'auto') {
if (hasLabel && autoLabelWidth && autoLabelWidth !== 'auto') {
const marginWidth = Math.max(
0,
Number.parseInt(autoLabelWidth, 10) - computedWidth.value

View File

@ -52,6 +52,7 @@ export interface FormItemContext extends FormItemProps {
isGroup: boolean
labelId: string
inputIds: string[]
hasLabel: boolean
addInputId: (id: string) => void
removeInputId: (id: string) => void
validate: (