Skip to content

Commit 896be8c

Browse files
talissoncostaclaude
andcommitted
refactor(value-editor): drop the E2E textarea fork
The E2E ? textarea : Highlight fork was added in 2022 as a TestCafe workaround. Playwright landed in March and drives a contenteditable with fill(), so every E2E assertion about this editor has been running against a textarea that only exists during tests. placeholder and readOnly only ever worked on that textarea, so they go with it, along with the three call sites passing them. Highlight takes role and aria-readonly from the caller rather than deriving them from onChange, so ValueEditor can name its read-only editors while the code blocks that also use Highlight stay unlabelled. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7dc842f commit 896be8c

6 files changed

Lines changed: 25 additions & 46 deletions

File tree

frontend/documentation/components/ValueEditor.stories.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ const Interactive = ({
1919
const [value, setValue] = useState(initialValue)
2020
return (
2121
<div style={{ maxWidth: width, padding: 16 }}>
22-
<ValueEditor {...props} value={value} onChange={setValue} />
22+
<ValueEditor
23+
data-test='valueEditor'
24+
{...props}
25+
value={value}
26+
onChange={setValue}
27+
/>
2328
</div>
2429
)
2530
}

frontend/web/components/Highlight.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ class Highlight extends React.Component {
158158
data-test={this.props['data-test']}
159159
id={this.props.id}
160160
aria-labelledby={this.props['aria-labelledby']}
161-
// Without a role a contenteditable is announced as plain text, and
162-
// aria-labelledby has nothing to name.
163-
role={this.props.onChange ? 'textbox' : undefined}
164-
aria-multiline={this.props.onChange ? true : undefined}
161+
// Set by the caller: a value field wants role=textbox so its label
162+
// names it, while the code blocks that also use Highlight are not
163+
// form controls and pass nothing.
164+
role={this.props.role}
165+
aria-readonly={this.props['aria-readonly']}
166+
aria-multiline={this.props.role === 'textbox' ? true : undefined}
165167
contentEditable={!!this.props.onChange}
166168
onBlur={this.onBlur}
167169
onFocus={this.onFocus}

frontend/web/components/SegmentOverrides.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ const SegmentOverrideInner = class Override extends React.Component {
280280
<div className='flex-fill overflow-hidden'>
281281
<ValueEditor
282282
label='Value'
283-
readOnly={readOnly}
284283
disabled={readOnly}
285284
value={v.value}
286285
data-test={`segment-override-value-${index}`}
@@ -304,7 +303,6 @@ const SegmentOverrideInner = class Override extends React.Component {
304303
label={`Segment Control Value - ${controlPercent}%`}
305304
value={v.value}
306305
data-test={`segment-override-value-${index}`}
307-
placeholder="Value e.g. 'big' "
308306
disabled={readOnly}
309307
onChange={
310308
readOnly

frontend/web/components/ValueEditor/ValueEditor.tsx

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ export interface ValueEditorProps {
1919
label?: ReactNode
2020
labelTooltip?: string
2121
language?: ValueEditorLanguage
22-
name?: string
2322
onBlur?: () => void
2423
onChange?: (value: string) => void
25-
// placeholder and readOnly only reach the editor under E2E, which swaps
26-
// Highlight for a plain textarea. Highlight renders its own
27-
// 'Enter a value...' and stops accepting input while disabled.
28-
placeholder?: string
29-
readOnly?: boolean
3024
value?: FlagsmithValue
3125
}
3226

@@ -36,11 +30,8 @@ const ValueEditor: FC<ValueEditorProps> = ({
3630
label,
3731
labelTooltip,
3832
language: languageProp,
39-
name,
4033
onBlur,
4134
onChange,
42-
placeholder,
43-
readOnly,
4435
value,
4536
...rest
4637
}) => {
@@ -96,32 +87,19 @@ const ValueEditor: FC<ValueEditorProps> = ({
9687
<div className='value-editor__field'>
9788
{showControls && <CopyValueButton value={text} />}
9889

99-
{E2E ? (
100-
<textarea
101-
aria-labelledby={label ? labelId : undefined}
102-
data-test={rest['data-test']}
103-
disabled={disabled}
104-
id={editorId}
105-
name={name}
106-
onBlur={onBlur}
107-
onChange={(e) => onChange?.(e.target.value)}
108-
placeholder={placeholder}
109-
readOnly={readOnly}
110-
value={text}
111-
/>
112-
) : (
113-
<Highlight
114-
aria-labelledby={label ? labelId : undefined}
115-
data-test={E2E ? rest['data-test'] : ''}
116-
disabled={disabled}
117-
id={editorId}
118-
onChange={disabled ? null : onChange}
119-
onBlur={disabled ? null : onBlur}
120-
className={language}
121-
>
122-
{text}
123-
</Highlight>
124-
)}
90+
<Highlight
91+
aria-labelledby={label ? labelId : undefined}
92+
aria-readonly={disabled || undefined}
93+
data-test={rest['data-test']}
94+
disabled={disabled}
95+
id={editorId}
96+
onChange={disabled ? null : onChange}
97+
onBlur={disabled ? null : onBlur}
98+
role='textbox'
99+
className={language}
100+
>
101+
{text}
102+
</Highlight>
125103
</div>
126104
</div>
127105
)

frontend/web/components/modals/create-feature/tabs/FeatureValueTab.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ const FeatureValueTab: FC<FeatureValueTabProps> = ({
379379
label={valueTitle}
380380
labelTooltip={getValueTooltip(hasVariations, isEdit)}
381381
data-test='featureValue'
382-
name='featureValue'
383382
className={`full-width${hasVariations ? ' code-medium' : ''}`}
384383
value={`${
385384
typeof initial_value === 'undefined' || initial_value === null
@@ -392,7 +391,6 @@ const FeatureValueTab: FC<FeatureValueTabProps> = ({
392391
})
393392
}}
394393
disabled={isDisabled}
395-
placeholder="e.g. 'big' "
396394
/>
397395
</div>
398396
{canCompareValue && (

frontend/web/components/mv/VariationValueInput/VariationValueInput.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export const VariationValueInput: React.FC<VariationValueProps> = ({
7676
data-test={`featureVariationValue${
7777
Utils.featureStateToValue(value) || index
7878
}`}
79-
name='featureValue'
8079
className='full-width code-medium'
8180
value={Utils.getTypedValue(Utils.featureStateToValue(value))}
8281
disabled={!canCreateFeature || disabled || readOnly}
@@ -97,7 +96,6 @@ export const VariationValueInput: React.FC<VariationValueProps> = ({
9796
...Utils.valueToFeatureState(newValue, false),
9897
})
9998
}}
100-
placeholder="e.g. 'big' "
10199
/>,
102100
)}
103101
</div>

0 commit comments

Comments
 (0)