Skip to content

Commit

Permalink
fix(FormControl): add size support when using plaintext
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Jul 24, 2023
1 parent f6388aa commit 452fea8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,6 @@ const FormControl: BsPrefixRefForwardingComponent<'input', FormControlProps> =

bsPrefix = useBootstrapPrefix(bsPrefix, 'form-control');

let classes;
if (plaintext) {
classes = { [`${bsPrefix}-plaintext`]: true };
} else {
classes = {
[bsPrefix]: true,
[`${bsPrefix}-${size}`]: size,
};
}

warning(
controlId == null || !id,
'`controlId` is ignored on `<FormControl>` when `id` is specified.',
Expand All @@ -151,10 +141,12 @@ const FormControl: BsPrefixRefForwardingComponent<'input', FormControlProps> =
id={id || controlId}
className={classNames(
className,
classes,
isValid && `is-valid`,
isInvalid && `is-invalid`,
type === 'color' && `${bsPrefix}-color`,
!plaintext && [bsPrefix],
plaintext && [`${bsPrefix}-plaintext`],
size && [`${bsPrefix}-${size}`],
type === 'color' && [`${bsPrefix}-color`],
isValid && 'is-valid',
isInvalid && 'is-invalid',
)}
/>
);
Expand Down
10 changes: 10 additions & 0 deletions test/FormControlSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe('<FormControl>', () => {
element.classList.contains('form-control-plaintext').should.be.true;
});

it('should support plaintext inputs with size', () => {
const { getByTestId } = render(
<FormControl plaintext size="sm" data-testid="test-id" />,
);

const element = getByTestId('test-id');
element.classList.length.should.equal(2);
element.classList.contains('form-control-sm').should.be.true;
});

it('should support type=color', () => {
const { getByTestId } = render(
<FormControl type="color" data-testid="test-id" />,
Expand Down

0 comments on commit 452fea8

Please sign in to comment.