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
FBJS: Fix getActiveElement w/o document
Summary:
Brings back #59.
  • Loading branch information
yungsters committed Jan 5, 2016
commit 2364a846f1c429eedf48edcdb34fd7fd11dd2978
22 changes: 22 additions & 0 deletions src/core/dom/__tests__/getActiveElement-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

'use strict';

jest.dontMock('getActiveElement');

var getActiveElement = require('getActiveElement');

describe('getActiveElement', () => {
it('returns body when there is no activeElement', () => {
var element = getActiveElement();
expect(element.tagName).toEqual('BODY');
});
});
8 changes: 7 additions & 1 deletion src/core/dom/getActiveElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
* @typechecks
*/

/* eslint-disable fb-www/typeof-undefined */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this, though.

Copy link
Member

Choose a reason for hiding this comment

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

👍

On Monday, January 4, 2016, Timothy Yung [email protected] wrote:

In src/core/dom/getActiveElement.js
#96 (comment):

@@ -10,13 +10,19 @@

  • @typechecks
    */

+/* eslint-disable fb-www/typeof-undefined */

Added this, though.


Reply to this email directly or view it on GitHub
https://github.com/facebook/fbjs/pull/96/files#r48808302.


/**
* Same as document.activeElement but wraps in a try-catch block. In IE it is
* not safe to call document.activeElement if there is nothing focused.
*
* The activeElement will be null only if the document body is not yet defined.
* The activeElement will be null only if the document or document body is not
* yet defined.
*/
function getActiveElement() /*?DOMElement*/ {
if (typeof document === 'undefined') {
return null;
}
try {
return document.activeElement || document.body;
} catch (e) {
Expand Down