Skip to content

Commit

Permalink
Fix #5440: InputText only print className once (#5441)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Nov 28, 2023
1 parent 05f9124 commit 8b149ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/lib/inputtext/InputText.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { KeyFilter } from '../keyfilter/KeyFilter';
import { Tooltip } from '../tooltip/Tooltip';
import { DomHandler, ObjectUtils, mergeProps } from '../utils/Utils';
import { DomHandler, ObjectUtils, classNames, mergeProps } from '../utils/Utils';
import { InputTextBase } from './InputTextBase';

export const InputText = React.memo(
Expand Down Expand Up @@ -69,7 +69,7 @@ export const InputText = React.memo(

const rootProps = mergeProps(
{
className: cx('root', { isFilled }),
className: classNames(props.className, cx('root', { isFilled })),
onBeforeInput: onBeforeInput,
onInput: onInput,
onKeyDown: onKeyDown,
Expand Down
12 changes: 12 additions & 0 deletions components/lib/inputtext/InputText.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ describe('InputText', () => {
expect(input).toHaveValue('');
expect(container).toMatchSnapshot();
});
test('when input has className only 1 className is printed', () => {
// Arrange
const { container } = render(<InputText className="jest" />);
const input = container.getElementsByTagName('input')[0];

// Act
fireEvent.input(input, { target: { value: 'jest' } });

// Act
expect(container).toMatchSnapshot();
expect(input).toHaveValue('jest');
});
test('when input is is set for validation only', () => {
// Arrange
const { container } = render(<InputText validateOnly keyfilter={`alpha`} />);
Expand Down
9 changes: 5 additions & 4 deletions components/lib/inputtext/InputTextBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ export const InputTextBase = ComponentBase.extend({
defaultProps: {
__TYPE: 'InputText',
__parentMetadata: null,
children: undefined,
className: null,
keyfilter: null,
validateOnly: false,
tooltip: null,
tooltipOptions: null,
onBeforeInput: null,
onInput: null,
onKeyDown: null,
onPaste: null,
children: undefined
tooltip: null,
tooltipOptions: null,
validateOnly: false
},

css: {
Expand Down
10 changes: 10 additions & 0 deletions components/lib/inputtext/__snapshots__/InputText.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`InputText when input has className only 1 className is printed 1`] = `
<div>
<input
class="jest p-inputtext p-component p-filled"
data-pc-name="inputtext"
data-pc-section="root"
/>
</div>
`;

exports[`InputText when input is blank it should not have filled state 1`] = `
<div>
<input
Expand Down

0 comments on commit 8b149ca

Please sign in to comment.