main
js 20 lines 496 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 export default function getActiveElement(doc: ?Document): ?Element {
11 doc = doc || (typeof document !== 'undefined' ? document : undefined);
12 if (typeof doc === 'undefined') {
13 return null;
14 }
15 try {
16 return doc.activeElement || doc.body;
17 } catch (e) {
18 return doc.body;
19 }
20 }