Skip to content

Commit

Permalink
[FormControl] Add fullWidth prop to FormControl context (#19369)
Browse files Browse the repository at this point in the history
  • Loading branch information
EsoterikStare authored and eps1lon committed Jan 24, 2020
1 parent 481cdd8 commit 0ad3b6d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/material-ui/src/FormControl/FormControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const FormControl = React.forwardRef(function FormControl(props, ref) {
error,
filled,
focused,
fullWidth,
hiddenLabel,
margin: (size === 'small' ? 'dense' : undefined) || margin,
onBlur: () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/material-ui/src/FormControl/FormControl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ describe('<FormControl />', () => {
setProps({ margin: 'dense' });
expect(formControlRef.current).to.have.property('margin', 'dense');
});

it('should have the fullWidth prop from the instance', () => {
const formControlRef = React.createRef();
const { setProps } = render(<FormControlled ref={formControlRef} />);

expect(formControlRef.current).to.have.property('fullWidth', false);

setProps({ fullWidth: true });
expect(formControlRef.current).to.have.property('fullWidth', true);
});
});

describe('callbacks', () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/material-ui/src/FormControl/useFormControl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { FormControlProps } from './FormControl';
// shut off automatic exporting
export {};

type ContextFromPropsKey = 'disabled' | 'error' | 'hiddenLabel' | 'margin' | 'required' | 'variant';
type ContextFromPropsKey =
| 'disabled'
| 'error'
| 'fullWidth'
| 'hiddenLabel'
| 'margin'
| 'required'
| 'variant';

export interface FormControlState extends Pick<FormControlProps, ContextFromPropsKey> {
adornedStart: boolean;
Expand Down

0 comments on commit 0ad3b6d

Please sign in to comment.