-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: TextField input width with textAfter
- Loading branch information
1 parent
f921dba
commit 4c753d5
Showing
19 changed files
with
323 additions
and
17 deletions.
There are no files selected for viewing
Binary file added
BIN
+1.27 KB
.../snapshots/b2c/components/TextField/TextField.component-test.tsx/empty.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.9 KB
...tField.component-test.tsx/plasma-b2c TextField -- textBefore,textAfter.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.6 KB
...ots/tokens-b2b/components/TextField/TextField.component-test.tsx/empty.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+50.3 KB
...lasma-web TextField -- _enumerationTypechip, _chipView, _chipValidator.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.7 KB
...tField.component-test.tsx/plasma-web TextField -- textBefore,textAfter.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+33 Bytes
(100%)
...d.component-test.tsx/plasma-web TextField keyboard navigation -- chips.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.58 KB
.../snapshots/web/components/TextField/TextField.component-test.tsx/empty.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+17.6 KB
...tField.component-test.tsx/plasma-web TextField -- textBefore,textAfter.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1 Byte
(100%)
.../TextFieldGroup.component-test.tsx/plasma-web TextFieldGroup -- _shape.snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/plasma-new-hope/src/components/TextField/getInputWidth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { CSSProperties } from 'react'; | ||
|
||
const INHERITED_PROPERTIES = [ | ||
'font', | ||
'letterSpacing', | ||
'textTransform', | ||
'fontKerning', | ||
'fontOpticalSizing', | ||
'fontSizeAdjust', | ||
'fontStretch', | ||
'fontVariant', | ||
'fontWeight', | ||
'fontVariationSettings', | ||
'fontSynthesis', | ||
'textIndent', | ||
] as Extract<keyof CSSStyleDeclaration, string>[]; | ||
|
||
const measureStyles = { | ||
position: 'absolute', | ||
top: '0px', | ||
left: '0px', | ||
width: '0px', | ||
height: '0px', | ||
visibility: 'hidden', | ||
overflow: 'scroll', | ||
whiteSpace: 'pre', | ||
} as CSSProperties; | ||
|
||
export function getInputWidth(element: HTMLInputElement, container: HTMLDivElement | null) { | ||
if (!element || !container) { | ||
return 0; | ||
} | ||
|
||
const measure = document.createElement('span'); | ||
measure.innerText = element.value || element.placeholder || ' '; | ||
Object.assign(measure.style, measureStyles); | ||
|
||
const styles = window.getComputedStyle(element); | ||
|
||
INHERITED_PROPERTIES.forEach((property) => { | ||
measure.style.setProperty(property, String(styles[property])); | ||
}); | ||
|
||
container.appendChild(measure); | ||
const width = measure.scrollWidth; | ||
container.removeChild(measure); | ||
return width; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.