Skip to content

Commit e8a2742

Browse files
mariush2Copilot
andauthored
fix: Max characters text height (#1205)
* fix: Max characters text height * fix: Max characters text height * chore: Bump 10.9.1 * fix: Uncontrolled init of text field character count * Update src/molecules/TextField/TextField.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 9e2ee4a commit e8a2742

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@equinor/amplify-component-lib",
3-
"version": "10.9.0",
3+
"version": "10.9.1",
44
"description": "Frontend Typescript components for the Amplify team",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/molecules/TextField/TextField.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { SkeletonBase } from 'src/molecules/Skeleton/SkeletonBase/SkeletonBase';
2424

2525
import styled, { css } from 'styled-components';
2626

27-
export type TextFieldProps = Omit<BaseProps, 'variant'> & {
27+
export type TextFieldProps = Omit<BaseProps, 'variant' | 'inputRef'> & {
2828
variant?: Variants;
2929
loading?: boolean;
3030
maxCharacters?: number;
@@ -41,6 +41,7 @@ interface WrapperProps {
4141

4242
const Wrapper = styled.div<WrapperProps>`
4343
position: relative;
44+
height: fit-content;
4445
input,
4546
textarea {
4647
color: ${colors.text.static_icons__default.rgba};
@@ -181,6 +182,18 @@ export const TextField: FC<TextFieldProps> = (props) => {
181182
}
182183
};
183184

185+
const handleOnTextFieldRender = (
186+
element: HTMLInputElement | HTMLTextAreaElement | null
187+
) => {
188+
if (
189+
props.maxCharacters &&
190+
element &&
191+
element.value.length !== characterCount
192+
) {
193+
setCharacterCount(element.value.length);
194+
}
195+
};
196+
184197
useEffect(() => {
185198
if (
186199
typeof props.value === 'string' &&
@@ -196,9 +209,13 @@ export const TextField: FC<TextFieldProps> = (props) => {
196209
$variant={usingVariant}
197210
$disabled={props.loading ? false : props.disabled}
198211
$helperRightWidth={helperRightWidth}
212+
style={{
213+
marginBottom: props.helperText ? 0 : `calc(${spacings.small} + 1rem)`,
214+
}}
199215
>
200216
<Base
201217
{...baseProps}
218+
inputRef={handleOnTextFieldRender}
202219
disabled={props.loading || props.disabled}
203220
onChange={handleOnChange as never} // Bypass TS error caused by union of input and textarea attributes
204221
/>

0 commit comments

Comments
 (0)