Skip to content

Commit

Permalink
fix(utils): handleMargin function cannot properly handle the width wh…
Browse files Browse the repository at this point in the history
…en margin is set to 4 values (#222)
  • Loading branch information
mengshang918 committed Jun 22, 2022
1 parent aad765f commit 70f9a4c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/utils/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CSSProperties } from 'react'
* @Author: jiangxiaowei
* @Date: 2020-05-30 15:05:13
* @Last Modified by: jiangxiaowei
* @Last Modified time: 2022-06-15 13:44:02
* @Last Modified time: 2022-06-22 18:23:08
*/
import type { TreeItems, TreeItem } from '../tree/types'
import type { Map } from './type'
Expand Down Expand Up @@ -403,8 +403,8 @@ export function toArray(param: string | Array<string>): Array<string> {
// 处理容器宽度
export const handleMargin = (style: CSSProperties): void => {
const { margin, width } = style
let marginRight: number | string = '0px'
let marginLeft: number | string = '0px'
let marginRight = style.marginRight || '0px'
let marginLeft = style.marginLeft || '0px'
if (width) {
if (margin) {
if (typeof margin === 'string') {
Expand All @@ -417,6 +417,10 @@ export const handleMargin = (style: CSSProperties): void => {
marginRight = marginArr[1]
marginLeft = marginArr[1]
}
if (marginArr.length === 4) {
marginRight = marginArr[1]
marginLeft = marginArr[3]
}
}
}
style.width = `calc(${style.width} - ${marginRight} - ${marginLeft})`
Expand Down

0 comments on commit 70f9a4c

Please sign in to comment.