Skip to content

Commit

Permalink
fix(FormControl): add size support when using plaintext (#6667)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Jul 25, 2023
1 parent f6388aa commit 57b4e29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/FormControl.tsx
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,11 @@ const FormControl: BsPrefixRefForwardingComponent<'input', FormControlProps> =
id={id || controlId}
className={classNames(
className,
classes,
isValid && `is-valid`,
isInvalid && `is-invalid`,
plaintext ? `${bsPrefix}-plaintext` : bsPrefix,
size && `${bsPrefix}-${size}`,
type === 'color' && `${bsPrefix}-color`,
isValid && 'is-valid',
isInvalid && 'is-invalid',
)}
/>
);
Expand Down
10 changes: 10 additions & 0 deletions test/FormControlSpec.tsx
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 57b4e29

Please sign in to comment.