Skip to content

Commit

Permalink
fix(comp:textarea): boxsizing data parse error in firefox (#1599)
Browse files Browse the repository at this point in the history
boxsizing data got from computed style is empty string in firefox, causing paseFloat to return NaN
  • Loading branch information
sallerli1 committed Jul 12, 2023
1 parent 12bf691 commit f68df61
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/components/textarea/src/utils/getBoxSizingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export interface BoxSizingData {
export function getBoxSizingData(node: HTMLElement): BoxSizingData {
const { boxSizing, paddingBottom, paddingTop, borderBottom, borderTop } = window.getComputedStyle(node)

const _paddingTop = parseFloat(paddingTop)
const _paddingBottom = parseFloat(paddingBottom)
const _borderTop = parseFloat(borderTop)
const _borderBottom = parseFloat(borderBottom)
const _paddingTop = parseSize(paddingTop)
const _paddingBottom = parseSize(paddingBottom)
const _borderTop = parseSize(borderTop)
const _borderBottom = parseSize(borderBottom)

return {
boxSizing,
Expand All @@ -33,3 +33,9 @@ export function getBoxSizingData(node: HTMLElement): BoxSizingData {
borderBottom: _borderBottom,
}
}

function parseSize(size: string): number {
const parsedSize = parseFloat(size)

return Number.isNaN(parsedSize) ? 0 : parsedSize
}

0 comments on commit f68df61

Please sign in to comment.