Skip to content

Commit

Permalink
Fixed expandable textarea and moved textarea to app-components
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhaeger committed Dec 2, 2024
1 parent 70ca6fb commit d2d27ff
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
51 changes: 51 additions & 0 deletions src/app-components/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from 'react';

import { Textarea } from '@digdir/designsystemet-react';
import type { CharacterLimitProps } from '@digdir/designsystemet-react/dist/types/components/form/CharacterCounter';

//import { Label } from 'your-component-library/Label'; // Adjust the import path accordingly

export interface TextAreaWithLabelProps {
id: string;
value: string;
onChange: (value: string) => void;
onBlur?: () => void;
readOnly?: boolean;
characterLimit?: CharacterLimitProps | undefined;
error?: boolean;
dataTestId?: string;
ariaDescribedBy?: string;
ariaLabel?: string;
autoComplete?: string;
style?: React.CSSProperties;
}

export const TextArea: React.FC<TextAreaWithLabelProps> = ({
id,
value,
onChange,
onBlur,
readOnly = false,
characterLimit,
error = false,
dataTestId,
ariaDescribedBy,
ariaLabel,
autoComplete,
style,
}) => (
<Textarea
id={id}
onChange={(e) => onChange(e.target.value)}
onBlur={onBlur}
readOnly={readOnly}
characterLimit={characterLimit}
error={error}
value={value}
data-testid={dataTestId}
aria-describedby={ariaDescribedBy}
aria-label={ariaLabel}
autoComplete={autoComplete}
style={style}
/>
);
20 changes: 9 additions & 11 deletions src/layout/TextArea/TextAreaComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';

import { Textarea } from '@digdir/designsystemet-react';

import { Label } from 'src/app-components/Label/Label';
import { getDescriptionId } from 'src/components/label/Label';
import { TextArea } from 'src/app-components/TextArea/TextArea';
import { FD } from 'src/features/formData/FormDataWrite';
import { useDataModelBindings } from 'src/features/formData/useDataModelBindings';
import { useLanguage } from 'src/features/language/useLanguage';
Expand Down Expand Up @@ -61,23 +59,23 @@ export function TextAreaComponent({ node, overrideDisplay }: ITextAreaProps) {
description={getDescriptionComponent()}
>
<ComponentStructureWrapper node={node}>
<Textarea
<TextArea
id={id}
onChange={(e) => setValue('simpleBinding', e.target.value)}
value={value}
onChange={(newValue) => setValue('simpleBinding', newValue)}
onBlur={debounce}
readOnly={readOnly}
characterLimit={!readOnly ? characterLimit : undefined}
error={!isValid}
value={value}
data-testid={id}
aria-describedby={
dataTestId={id}
ariaDescribedBy={
overrideDisplay?.renderedInTable !== true && textResourceBindings?.description
? getDescriptionId(id)
? `description-${id}`
: undefined
}
aria-label={overrideDisplay?.renderedInTable === true ? langAsString(textResourceBindings?.title) : undefined}
ariaLabel={overrideDisplay?.renderedInTable === true ? langAsString(textResourceBindings?.title) : undefined}
autoComplete={autocomplete}
style={{ height: '150px' }}
style={{ minHeight: '150px' }}
/>
</ComponentStructureWrapper>
</Label>
Expand Down

0 comments on commit d2d27ff

Please sign in to comment.