Skip to content

Commit 8113a80

Browse files
Merge pull request #183 from open-formulieren/issue/4636-translation-tab-unusable-with-long-values
🐛 [open-formulieren/open-forms#4636] Preventing large values from breaking the table
2 parents c768a2d + 4b009bb commit 8113a80

File tree

4 files changed

+82
-11
lines changed

4 files changed

+82
-11
lines changed

src/components/builder/i18n.stories.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {expect, userEvent, waitFor, within} from '@storybook/test';
33
import {Formik} from 'formik';
44

55
import {TextField} from '@/components/formio';
6+
import {withFormik} from '@/sb-decorators';
67

78
import {ComponentTranslations} from './i18n';
89

@@ -108,3 +109,26 @@ export const Default: Story = {
108109
expect(translationField2).toBeNull();
109110
},
110111
};
112+
113+
export const LongStringsWrap: StoryObj<typeof ComponentTranslations<DummyComponent>> = {
114+
decorators: [withFormik],
115+
args: {
116+
propertyLabels: {
117+
label: 'Label',
118+
},
119+
},
120+
parameters: {
121+
formik: {
122+
initialValues: {
123+
label: Array(100).fill('a').join(''),
124+
openForms: {
125+
translations: {
126+
nl: {
127+
label: 'Insgelijks',
128+
},
129+
},
130+
},
131+
},
132+
},
133+
},
134+
};

src/components/builder/i18n.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {AnyComponentSchema} from '@/types/schemas';
1212
import {Component, TextField} from '../formio';
1313
import ComponentLabel from '../formio/component-label';
1414
import './i18n.scss';
15+
import './table.scss';
1516

1617
type ExtractTranslatableProperties<T> = T extends OFExtensions<infer TK> ? TK : never;
1718
type StringValueProperties<S> = S extends AnyComponentSchema
@@ -53,10 +54,13 @@ export function ComponentTranslations<S extends AnyComponentSchema>({
5354

5455
return (
5556
<Component type="datagrid">
56-
<table className="table table-bordered">
57+
<table className="table table-bordered offb-table">
5758
<thead>
5859
<tr className="offb-i18n-header">
59-
<td colSpan={2} className="offb-i18n-header__label">
60+
<td
61+
colSpan={2}
62+
className="offb-i18n-header__label offb-table__col offb-table__col--width-50"
63+
>
6064
<ComponentLabel
6165
label={
6266
<FormattedMessage
@@ -70,7 +74,7 @@ export function ComponentTranslations<S extends AnyComponentSchema>({
7074
})}
7175
/>
7276
</td>
73-
<td className="offb-i18n-header__tab-container">
77+
<td className="offb-i18n-header__tab-container offb-table__col offb-table__col--width-50">
7478
<ul className={`nav nav-tabs offb-i18n-header__tabs`}>
7579
{supportedLanguageCodes.map(code => (
7680
<li key={code} className={clsx('nav-item', {active: code === activeLanguage})}>
@@ -92,19 +96,19 @@ export function ComponentTranslations<S extends AnyComponentSchema>({
9296
</tr>
9397

9498
<tr>
95-
<th style={{width: '20%'}}>
99+
<th className="offb-table__col offb-table__col--width-25">
96100
<FormattedMessage
97101
description="Translations: location column header"
98102
defaultMessage="Location"
99103
/>
100104
</th>
101-
<th style={{width: '35%'}}>
105+
<th className="offb-table__col offb-table__col--width-25">
102106
<FormattedMessage
103107
description="Translations: property column header"
104108
defaultMessage="Value"
105109
/>
106110
</th>
107-
<th style={{borderTop: 'none'}}>
111+
<th className="offb-table__col offb-table__col--width-50">
108112
<FormattedMessage
109113
description="Translations: translation column header"
110114
defaultMessage="Translations"
@@ -122,7 +126,10 @@ export function ComponentTranslations<S extends AnyComponentSchema>({
122126
</span>
123127
</td>
124128
<td>
125-
<div aria-describedby={`component-translation-property-${property}`}>
129+
<div
130+
aria-describedby={`component-translation-property-${property}`}
131+
className="offb-table__content offb-table__content--allow-break"
132+
>
126133
{(values?.[property] || '-') as string}
127134
</div>
128135
</td>

src/components/builder/table.scss

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.offb-table {
2+
// Ensures that the column widths are respected
3+
table-layout: fixed;
4+
width: 100%;
5+
6+
&__content {
7+
&--allow-break {
8+
overflow-wrap: break-word;
9+
hyphens: auto;
10+
}
11+
}
12+
13+
&__col {
14+
&--width-25 {
15+
width: 25%;
16+
}
17+
&--width-50 {
18+
width: 50%;
19+
}
20+
}
21+
}

src/components/builder/values/i18n.tsx

+23-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,20 @@ export function ValuesTranslations<S>({name, withOptionDescription}: ValuesTrans
4545
<>
4646
<tr key={`option-${index}`}>
4747
<td>
48-
<span id={`option-${index}-label`}>{label}</span>
48+
<span
49+
id={`option-${index}-label`}
50+
className="offb-table__content offb-table__content--allow-break"
51+
>
52+
{label}
53+
</span>
4954
</td>
5055
<td>
51-
<div aria-describedby={`option-${index}-label`}>{value || '-'}</div>
56+
<div
57+
aria-describedby={`option-${index}-label`}
58+
className="offb-table__content offb-table__content--allow-break"
59+
>
60+
{value || '-'}
61+
</div>
5262
</td>
5363
<td>
5464
<TextField
@@ -85,14 +95,23 @@ export function ValuesTranslations<S>({name, withOptionDescription}: ValuesTrans
8595
description="Label for option description location"
8696
defaultMessage="Option description (<option></option>)"
8797
values={{
88-
option: () => <code>{value || '-'}</code>,
98+
option: () => (
99+
<code className="offb-table__content offb-table__content--allow-break">
100+
{value || '-'}
101+
</code>
102+
),
89103
}}
90104
/>
91105
</span>
92106
</td>
93107

94108
<td>
95-
<div aria-describedby={`option-${index}-label`}>{description || '-'}</div>
109+
<div
110+
aria-describedby={`option-${index}-label`}
111+
className="offb-table__content offb-table__content--allow-break"
112+
>
113+
{description || '-'}
114+
</div>
96115
</td>
97116

98117
<td>

0 commit comments

Comments
 (0)