Skip to content

Commit 4c5c489

Browse files
poi33Persijn David Kwekkeboom
andauthored
fix(textfield): change validation message order (#4104)
Co-authored-by: Persijn David Kwekkeboom <pekw01@lillestrom.kommune.no>
1 parent 81fc117 commit 4c5c489

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

.changeset/yummy-foxes-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@digdir/designsystemet-react": patch
3+
---
4+
5+
**Textfield**: Move counter error message before error

packages/react/src/components/textfield/textfield.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ describe('Textfield', () => {
127127

128128
expect(screen.getAllByText('1 tegn for mye')[0]).toBeInTheDocument();
129129
});
130+
131+
it('Render counter before error validation messages', () => {
132+
render({
133+
value: 'lorem',
134+
label: 'test',
135+
counter: 2,
136+
error: 'Other invalid condition',
137+
});
138+
139+
const countText = screen.getAllByText('3 tegn for mye')[0];
140+
const errorText = screen.getByText('Other invalid condition');
141+
expect(countText.compareDocumentPosition(errorText)).toBe(4);
142+
});
130143
});
131144

132145
const render = (

packages/react/src/components/textfield/textfield.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ export const Textfield = forwardRef<
130130
)}
131131
{suffix === undefined || <FieldAffix>{suffix}</FieldAffix>}
132132
</FieldAffixes>
133-
{!!error && <ValidationMessage>{error}</ValidationMessage>}
134133
{!!counter && (
135134
<Field.Counter
136135
{...(typeof counter === 'number' ? { limit: counter } : counter)}
137136
/>
138137
)}
138+
{!!error && <ValidationMessage>{error}</ValidationMessage>}
139139
</Field>
140140
);
141141
});

0 commit comments

Comments
 (0)