Skip to content

Commit

Permalink
fix(form-item): label text is in wrong position when `label-align="le…
Browse files Browse the repository at this point in the history
…ft"` and `require-mark-placement="left"` and `label-placement="left"`, closes #3871
  • Loading branch information
07akioni committed Oct 29, 2022
1 parent afea462 commit 9878b06
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
### Fixes

- Fix `n-image` to preview the image, press and drag the left mouse click,closes [#3950](https://github.com/tusen-ai/naive-ui/issues/3950).
- Fix `n-form-item`'s label text is in wrong position when `label-align="left"` and `require-mark-placement="left"` and `label-placement="left"`, closes [#3871](https://github.com/tusen-ai/naive-ui/issues/3871).

### i18n

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
### Fixes

- 修复 `n-image` 进行图片预览只可以按住鼠标左键拖拽,关闭 [#3950](https://github.com/tusen-ai/naive-ui/issues/3950)
- 修复 `n-form-item``label-align="left"` 并且 `require-mark-placement="left"` 并且 `label-placement="left"` 时标签文本显示位置有问题,关闭 [#3871](https://github.com/tusen-ai/naive-ui/issues/3871)

### i18n

Expand Down
45 changes: 33 additions & 12 deletions src/form/src/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export default defineComponent({
const { mergedSize: mergedSizeRef } = formItemSizeRefs
const {
mergedLabelPlacement: labelPlacementRef,
mergedLabelAlign: labelTextAlignRef
mergedLabelAlign: labelTextAlignRef,
mergedRequireMarkPlacement: mergedRequireMarkPlacementRef
} = formItemMiscRefs
const renderExplainsRef = ref<
Array<{
Expand Down Expand Up @@ -425,22 +426,40 @@ export default defineComponent({
}
return cssVars
})
const themeClassHandle = useThemeClass(
'form-item',
computed(() => {
return `${mergedSizeRef.value[0]}${labelPlacementRef.value[0]}${
labelTextAlignRef.value?.[0] || ''
}`
}),
cssVarsRef,
props
)
const themeClassHandle = inlineThemeDisabled
? useThemeClass(
'form-item',
computed(() => {
return `${mergedSizeRef.value[0]}${labelPlacementRef.value[0]}${
labelTextAlignRef.value?.[0] || ''
}`
}),
cssVarsRef,
props
)
: undefined
const reverseColSpaceRef = computed(() => {
// label placement left
// require-mark-placement | label align | areas (1fr auto)
// left | left | mark text (need reverse)
// left | right | mark text (okay)
// right | left | mark text (okay)
// right | right | mark text (okay)
// right-hanging | left | text mark (okay)
// right-hanging | right | text mark (okay)
return (
labelPlacementRef.value === 'left' &&
mergedRequireMarkPlacementRef.value === 'left' &&
labelTextAlignRef.value === 'left'
)
})
return {
labelElementRef,
mergedClsPrefix: mergedClsPrefixRef,
mergedRequired: mergedRequiredRef,
feedbackId: feedbackIdRef,
renderExplains: renderExplainsRef,
reverseColSpace: reverseColSpaceRef,
...formItemMiscRefs,
...formItemSizeRefs,
...exposedRef,
Expand Down Expand Up @@ -492,7 +511,9 @@ export default defineComponent({
class={[
labelProps?.class,
`${mergedClsPrefix}-form-item-label`,
`${mergedClsPrefix}-form-item-label--${mergedRequireMarkPlacement}-mark`
`${mergedClsPrefix}-form-item-label--${mergedRequireMarkPlacement}-mark`,
this.reverseColSpace &&
`${mergedClsPrefix}-form-item-label--reverse-columns-space`
]}
style={this.mergedLabelStyle as any}
ref="labelElementRef"
Expand Down
3 changes: 3 additions & 0 deletions src/form/src/styles/form-item.cssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export default cB('form-item', `
flex-shrink: 0;
flex-grow: 0;
`, [
cM('reverse-columns-space', `
grid-template-columns: auto 1fr;
`),
cM('left-mark', `
grid-template-areas:
"mark text"
Expand Down

0 comments on commit 9878b06

Please sign in to comment.