Skip to content

Commit e51652d

Browse files
eps1lonoliviertassinari
authored andcommitted
[InputBase] Fix onFilled/onEmpty being called during render (#15319)
1 parent 6a6e360 commit e51652d

File tree

2 files changed

+1
-51
lines changed

2 files changed

+1
-51
lines changed

packages/material-ui/src/InputBase/InputBase.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,14 @@ class InputBase extends React.Component {
156156
constructor(props) {
157157
super(props);
158158
this.isControlled = props.value != null;
159-
if (this.isControlled) {
160-
this.checkDirty(props);
161-
}
162159
}
163160

164161
state = {
165162
focused: false,
166163
};
167164

168165
componentDidMount() {
169-
if (!this.isControlled) {
170-
this.checkDirty(this.inputRef);
171-
}
166+
this.checkDirty(this.isControlled ? this.props : this.inputRef);
172167
}
173168

174169
componentDidUpdate(prevProps) {

packages/material-ui/src/InputBase/InputBase.test.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -396,51 +396,6 @@ describe('<InputBase />', () => {
396396
});
397397
});
398398

399-
describe('componentDidMount', () => {
400-
let wrapper;
401-
let instance;
402-
403-
before(() => {
404-
wrapper = mount(<NakedInputBase classes={classes} />);
405-
instance = wrapper.find('InputBase').instance();
406-
});
407-
408-
beforeEach(() => {
409-
instance.checkDirty = spy();
410-
});
411-
412-
it('should not call checkDirty if controlled', () => {
413-
instance.isControlled = true;
414-
instance.componentDidMount();
415-
assert.strictEqual(instance.checkDirty.callCount, 0);
416-
});
417-
418-
it('should call checkDirty if controlled', () => {
419-
instance.isControlled = false;
420-
instance.componentDidMount();
421-
assert.strictEqual(instance.checkDirty.callCount, 1);
422-
});
423-
424-
it('should call checkDirty with input value', () => {
425-
instance.isControlled = false;
426-
instance.inputRef = 'woofinput';
427-
instance.componentDidMount();
428-
assert.strictEqual(instance.checkDirty.calledWith(instance.inputRef), true);
429-
});
430-
431-
it('should call or not call checkDirty consistently', () => {
432-
instance.isControlled = true;
433-
instance.componentDidMount();
434-
assert.strictEqual(instance.checkDirty.callCount, 0);
435-
instance.isControlled = false;
436-
instance.componentDidMount();
437-
assert.strictEqual(instance.checkDirty.callCount, 1);
438-
instance.isControlled = true;
439-
instance.componentDidMount();
440-
assert.strictEqual(instance.checkDirty.callCount, 1);
441-
});
442-
});
443-
444399
describe('mount', () => {
445400
it('should be able to access the native input', () => {
446401
const handleRef = spy();

0 commit comments

Comments
 (0)