Skip to content

Commit c588221

Browse files
lee-chasetw15egankodiakhq[bot]
authored
fix: remove icon from readonly text input (#12382)
* fix: remove icon from readonly text input * chore: correct merge * chore: fix text input tests Co-authored-by: TJ Egan <tw15egan@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 38244d6 commit c588221

File tree

5 files changed

+24
-46
lines changed

5 files changed

+24
-46
lines changed

packages/react/src/components/FluidTextInput/__tests__/FluidTextInput-test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe('FluidTextInput', () => {
284284
it('should respect readOnly prop', () => {
285285
const onChange = jest.fn();
286286
const onClick = jest.fn();
287-
const { container } = render(
287+
render(
288288
<FluidTextInput
289289
id="input-1"
290290
labelText="FluidTextInput label"
@@ -302,12 +302,6 @@ describe('FluidTextInput', () => {
302302
userEvent.type(screen.getByRole('textbox'), 'x');
303303
expect(screen.getByRole('textbox')).not.toHaveValue('x');
304304
expect(onChange).toHaveBeenCalledTimes(0);
305-
306-
// Should display the "read-only" icon
307-
const icon = container.querySelector(
308-
`svg.${prefix}--text-input__readonly-icon`
309-
);
310-
expect(icon).toBeInTheDocument();
311305
});
312306
});
313307
});

packages/react/src/components/TextInput/TextInput.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ const TextInput = React.forwardRef(function TextInput(
142142
[`${prefix}--text-input__invalid-icon`]:
143143
normalizedProps.invalid || normalizedProps.warn,
144144
[`${prefix}--text-input__invalid-icon--warning`]: normalizedProps.warn,
145-
[`${prefix}--text-input__readonly-icon`]: readOnly,
146145
});
147146

148147
const counterClasses = classNames(`${prefix}--label`, {

packages/react/src/components/TextInput/__tests__/TextInput-test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ describe('TextInput', () => {
295295
it('should respect readOnly prop', () => {
296296
const onChange = jest.fn();
297297
const onClick = jest.fn();
298-
const { container } = render(
298+
render(
299299
<TextInput
300300
id="input-1"
301301
labelText="TextInput label"
@@ -313,12 +313,6 @@ describe('TextInput', () => {
313313
userEvent.type(screen.getByRole('textbox'), 'x');
314314
expect(screen.getByRole('textbox')).not.toHaveValue('x');
315315
expect(onChange).toHaveBeenCalledTimes(0);
316-
317-
// Should display the "read-only" icon
318-
const icon = container.querySelector(
319-
`svg.${prefix}--text-input__readonly-icon`
320-
);
321-
expect(icon).toBeInTheDocument();
322316
});
323317

324318
it('should not render counter with only enableCounter prop passed in', () => {

packages/react/src/internal/useNormalizedInputProps.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import React from 'react';
9-
import { WarningFilled, WarningAltFilled, EditOff } from '@carbon/icons-react';
9+
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
1010
import { usePrefix } from './usePrefix';
1111

1212
/**
@@ -65,28 +65,24 @@ export function useNormalizedInputProps({
6565
helperId: `${id}-helper-text`,
6666
};
6767

68-
if (readOnly) {
69-
normalizedProps.icon = EditOff;
70-
} else {
71-
if (normalizedProps.invalid) {
72-
normalizedProps.icon = WarningFilled;
73-
normalizedProps.validation = (
74-
<div
75-
className={`${prefix}--form-requirement`}
76-
id={normalizedProps.invalidId}>
77-
{invalidText}
78-
</div>
79-
);
80-
} else if (normalizedProps.warn) {
81-
normalizedProps.icon = WarningAltFilled;
82-
normalizedProps.validation = (
83-
<div
84-
className={`${prefix}--form-requirement`}
85-
id={normalizedProps.warnId}>
86-
{warnText}
87-
</div>
88-
);
89-
}
68+
if (normalizedProps.invalid) {
69+
normalizedProps.icon = WarningFilled;
70+
normalizedProps.validation = (
71+
<div
72+
className={`${prefix}--form-requirement`}
73+
id={normalizedProps.invalidId}>
74+
{invalidText}
75+
</div>
76+
);
77+
} else if (normalizedProps.warn) {
78+
normalizedProps.icon = WarningAltFilled;
79+
normalizedProps.validation = (
80+
<div
81+
className={`${prefix}--form-requirement`}
82+
id={normalizedProps.warnId}>
83+
{warnText}
84+
</div>
85+
);
9086
}
9187

9288
return normalizedProps;

packages/styles/scss/components/text-input/_text-input.scss

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,13 @@
9494
width: 100%;
9595
}
9696

97-
.#{$prefix}--text-input__invalid-icon,
98-
.#{$prefix}--text-input__readonly-icon {
97+
.#{$prefix}--text-input__invalid-icon {
9998
position: absolute;
10099
// top/transform used to center invalid icon in IE11
101100
top: 50%;
102101
right: $spacing-05;
103-
transform: translateY(-50%);
104-
}
105-
106-
.#{$prefix}--text-input__invalid-icon {
107102
fill: $support-error;
103+
transform: translateY(-50%);
108104
}
109105

110106
.#{$prefix}--text-input__invalid-icon--warning {
@@ -175,8 +171,7 @@
175171
}
176172

177173
.#{$prefix}--text-input--invalid,
178-
.#{$prefix}--text-input--warning,
179-
.#{$prefix}--text-input-wrapper--readonly .#{$prefix}--text-input {
174+
.#{$prefix}--text-input--warning {
180175
padding-right: $spacing-08;
181176
}
182177

0 commit comments

Comments
 (0)