UNPKG

2.77 kBJavaScriptView Raw
1var $625cf83917e112ad$exports = require("./utils.main.js");
2var $hrHul$react = require("react");
3var $hrHul$reactariautils = require("@react-aria/utils");
4
5
6function $parcel$export(e, n, v, s) {
7 Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8}
9
10$parcel$export(module.exports, "useFocus", () => $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6);
11/*
12 * Copyright 2020 Adobe. All rights reserved.
13 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License. You may obtain a copy
15 * of the License at http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software distributed under
18 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19 * OF ANY KIND, either express or implied. See the License for the specific language
20 * governing permissions and limitations under the License.
21 */ // Portions of the code in this file are based on code from react.
22// Original licensing for the following can be found in the
23// NOTICE file in the root directory of this source tree.
24// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
25
26
27
28function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
29 let { isDisabled: isDisabled, onFocus: onFocusProp, onBlur: onBlurProp, onFocusChange: onFocusChange } = props;
30 const onBlur = (0, $hrHul$react.useCallback)((e)=>{
31 if (e.target === e.currentTarget) {
32 if (onBlurProp) onBlurProp(e);
33 if (onFocusChange) onFocusChange(false);
34 return true;
35 }
36 }, [
37 onBlurProp,
38 onFocusChange
39 ]);
40 const onSyntheticFocus = (0, $625cf83917e112ad$exports.useSyntheticBlurEvent)(onBlur);
41 const onFocus = (0, $hrHul$react.useCallback)((e)=>{
42 // Double check that document.activeElement actually matches e.target in case a previously chained
43 // focus handler already moved focus somewhere else.
44 const ownerDocument = (0, $hrHul$reactariautils.getOwnerDocument)(e.target);
45 if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {
46 if (onFocusProp) onFocusProp(e);
47 if (onFocusChange) onFocusChange(true);
48 onSyntheticFocus(e);
49 }
50 }, [
51 onFocusChange,
52 onFocusProp,
53 onSyntheticFocus
54 ]);
55 return {
56 focusProps: {
57 onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
58 onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : undefined
59 }
60 };
61}
62
63
64//# sourceMappingURL=useFocus.main.js.map