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

[FormControl] Add fullWidth prop to FormControl context #19369

Merged
merged 2 commits into from
Jan 24, 2020
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
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');
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it might be a good place for this additional test, but if there is a better way/location, let me know.

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'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is correct or even necessary, but it seems like a type update would be good to do for anything that returns the updated context object.

| 'hiddenLabel'
| 'margin'
| 'required'
| 'variant';

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