Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Fix bug: '#3940 Validate function works incorrect with attribute validateOnFocusOut'",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('TextField', () => {

const renderedDOM: HTMLElement = renderIntoDocument(
<TextField
prefix={ examplePrefix}
prefix={ examplePrefix }
suffix={ exampleSuffix }
/>
);
Expand Down Expand Up @@ -287,6 +287,11 @@ describe('TextField', () => {

ReactTestUtils.Simulate.focus(inputDOM);
expect(validationCallCount).toEqual(2);

ReactTestUtils.Simulate.input(inputDOM, mockEvent('the input '));
ReactTestUtils.Simulate.input(inputDOM, mockEvent('the input value'));
ReactTestUtils.Simulate.focus(inputDOM);
expect(validationCallCount).toEqual(3);
});

it('should trigger validation only on blur', () => {
Expand All @@ -305,12 +310,17 @@ describe('TextField', () => {
);

const inputDOM: HTMLInputElement = renderedDOM.getElementsByTagName('input')[0];
ReactTestUtils.Simulate.focus(inputDOM);
ReactTestUtils.Simulate.input(inputDOM, mockEvent('the input value'));
expect(validationCallCount).toEqual(1);

ReactTestUtils.Simulate.blur(inputDOM);
expect(validationCallCount).toEqual(2);

ReactTestUtils.Simulate.input(inputDOM, mockEvent('the input va'));
ReactTestUtils.Simulate.input(inputDOM, mockEvent('the input value'));

ReactTestUtils.Simulate.blur(inputDOM);
expect(validationCallCount).toEqual(3);
});

it('should trigger validation on both blur and focus', () => {
Expand All @@ -335,9 +345,20 @@ describe('TextField', () => {

ReactTestUtils.Simulate.focus(inputDOM);
expect(validationCallCount).toEqual(2);

ReactTestUtils.Simulate.input(inputDOM, mockEvent('value before foc'));
ReactTestUtils.Simulate.input(inputDOM, mockEvent('value before focus'));
ReactTestUtils.Simulate.focus(inputDOM);
expect(validationCallCount).toEqual(3);

ReactTestUtils.Simulate.input(inputDOM, mockEvent('value before blur'));
ReactTestUtils.Simulate.blur(inputDOM);
expect(validationCallCount).toEqual(3);
expect(validationCallCount).toEqual(4);

ReactTestUtils.Simulate.input(inputDOM, mockEvent('value before bl'));
ReactTestUtils.Simulate.input(inputDOM, mockEvent('value before blur'));
ReactTestUtils.Simulate.blur(inputDOM);
expect(validationCallCount).toEqual(5);
});

it('should not trigger validation on component mount', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,10 @@ export class TextField extends BaseComponent<ITextFieldProps, ITextFieldState> i
}

private _validate(value: string | undefined): void {
const { validateOnFocusIn, validateOnFocusOut } = this.props;

// In case of _validate called multi-times during executing validate logic with promise return.
if (this._latestValidateValue === value) {
if (this._latestValidateValue === value && !(validateOnFocusIn || validateOnFocusOut)) {
return;
}

Expand Down