diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2021-03-16 22:17:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-16 22:17:25 +0100 |
commit | dff0dc0d6af9834f03902fe260b51a15de3ab498 (patch) | |
tree | ea14daa29b8ace004d32ccca430581b1191ab935 /tests | |
parent | e31cf579a0f3e64250af2e7269eef2e6c6e3d8fb (diff) | |
download | jquery-ui-dff0dc0d6af9834f03902fe260b51a15de3ab498.tar.gz jquery-ui-dff0dc0d6af9834f03902fe260b51a15de3ab498.zip |
Tests: Fix the "dialog: core: focus tabbable" test in IE
In IE in jQuery 3.4+ a sequence:
```js
$( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" );
```
doesn't end up with a focused input. However, in this test we only want to check
that the last focused input receives the focus back when `_focusTabbable()` is
called which in reality doesn't happen so quickly so let's avoid the issue by
waiting a bit.
Ref jquery/jquery#4856
Closes gh-1951
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/dialog/core.js | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/tests/unit/dialog/core.js b/tests/unit/dialog/core.js index 169734f1c..171d2789e 100644 --- a/tests/unit/dialog/core.js +++ b/tests/unit/dialog/core.js @@ -120,12 +120,32 @@ QUnit.test( "focus tabbable", function( assert ) { function step1() { checkFocus( "<div><input><input></div>", options, function( done ) { var input = element.find( "input" ).last().trigger( "focus" ).trigger( "blur" ); - element.dialog( "instance" )._focusTabbable(); - setTimeout( function() { - assert.equal( document.activeElement, input[ 0 ], - "1. an element that was focused previously." ); - done(); - } ); + + // Support: IE 11+ + // In IE in jQuery 3.4+ a sequence: + // $( inputNode ).trigger( "focus" ).trigger( "blur" ).trigger( "focus" ) + // doesn't end up with a focused input. See: + // https://github.com/jquery/jquery/issues/4856 + // However, in this test we only want to check that the last focused + // input receives the focus back when `_focusTabbable()` is called + // which in reality doesn't happen so quickly so let's avoid the issue + // by waiting a bit. + if ( document.documentMode ) { + setTimeout( function() { + focusTabbableAndAssert(); + }, 500 ); + } else { + focusTabbableAndAssert(); + } + + function focusTabbableAndAssert() { + element.dialog( "instance" )._focusTabbable(); + setTimeout( function() { + assert.equal( document.activeElement, input[ 0 ], + "1. an element that was focused previously." ); + done(); + } ); + } }, step2 ); } |