Skip to content

Commit

Permalink
fix: fix form-item labelWidth and wrapperWidth error
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyunwan committed Jul 5, 2022
1 parent 38d7afd commit 6e74041
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/components/src/__builtins__/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './utils'
export * from './portal'
export * from './loading'
export * from './types'
export * from './style'
8 changes: 8 additions & 0 deletions packages/components/src/__builtins__/shared/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function getStyleNumber(value: string | number) {
const num = Number(value)
if (isNaN(num)) {
return value
} else {
return `${value}px`
}
}
2 changes: 1 addition & 1 deletion packages/components/src/__builtins__/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function isVnode(element: any): boolean {
)
}

export function isVueOptions(options) {
export function isVueOptions(options: any) {
return (
options &&
(typeof options.template === 'string' ||
Expand Down
19 changes: 14 additions & 5 deletions packages/components/src/form-item/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import {
Warning,
} from '@element-plus/icons-vue'
import { useFormLayout, FormLayoutShallowContext } from '../form-layout'
import { composeExport, resolveComponent, stylePrefix } from '../__builtins__'
import {
composeExport,
resolveComponent,
stylePrefix,
getStyleNumber,
} from '../__builtins__'
import { Component } from 'vue'
import { ElTooltip, ElIcon } from 'element-plus'
import ResizeObserver from 'resize-observer-polyfill'
Expand Down Expand Up @@ -200,12 +205,16 @@ export const FormBaseItem = defineComponent({
let enableCol = false
if (labelWidth || wrapperWidth) {
if (labelWidth) {
labelStyle.width = `${labelWidth}px`
labelStyle.maxWidth = `${labelWidth}px`
labelStyle.width =
labelWidth === 'auto' ? undefined : getStyleNumber(labelWidth)
labelStyle.maxWidth =
labelWidth === 'auto' ? undefined : getStyleNumber(labelWidth)
}
if (wrapperWidth) {
wrapperStyle.width = `${wrapperWidth}px`
wrapperStyle.maxWidth = `${wrapperWidth}px`
wrapperStyle.width =
wrapperWidth === 'auto' ? undefined : getStyleNumber(wrapperWidth)
wrapperStyle.maxWidth =
wrapperWidth === 'auto' ? undefined : getStyleNumber(wrapperWidth)
}
// 栅格模式
} else if (labelCol || wrapperCol) {
Expand Down

0 comments on commit 6e74041

Please sign in to comment.