Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5440: InputText only print className once #5441

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading