@clayui/shared
Advanced tools
Comparing version 3.67.0 to 3.69.0
@@ -5,3 +5,8 @@ /** | ||
*/ | ||
import React from 'react'; | ||
import React, { Children } from 'react'; | ||
import { useFocusManagement } from './useFocusManagement'; | ||
declare type Children = React.ReactElement & { | ||
ref?: React.MutableRefObject<HTMLElement>; | ||
}; | ||
declare type ChildrenFunction = Children | ((focusManager: ReturnType<typeof useFocusManagement>) => Children); | ||
declare type Props = { | ||
@@ -18,5 +23,4 @@ /** | ||
arrowKeysUpDown?: boolean; | ||
children: React.ReactElement & { | ||
ref?: React.MutableRefObject<HTMLElement>; | ||
}; | ||
children: ChildrenFunction; | ||
onFocus?: (element: HTMLElement) => void; | ||
}; | ||
@@ -28,3 +32,3 @@ /** | ||
*/ | ||
export declare const FocusScope: ({ arrowKeysLeftRight, arrowKeysUpDown, children, }: Props) => JSX.Element; | ||
export declare const FocusScope: ({ arrowKeysLeftRight, arrowKeysUpDown, children, onFocus, }: Props) => JSX.Element; | ||
export {}; |
@@ -38,3 +38,4 @@ "use strict"; | ||
arrowKeysUpDown = _ref$arrowKeysUpDown === void 0 ? true : _ref$arrowKeysUpDown, | ||
children = _ref.children; | ||
children = _ref.children, | ||
onFocus = _ref.onFocus; | ||
@@ -51,8 +52,20 @@ var elRef = _react.default.useRef(null); | ||
if (arrowKeysUpDown && key === _Keys.Keys.Down || arrowKeysLeftRight && key === _Keys.Keys.Right || key === _Keys.Keys.Tab && !shiftKey) { | ||
if (focusManager.focusNext()) { | ||
var next = focusManager.focusNext(); | ||
if (next) { | ||
event.preventDefault(); | ||
if (onFocus) { | ||
onFocus(next); | ||
} | ||
} | ||
} else if (arrowKeysUpDown && key === _Keys.Keys.Up || arrowKeysLeftRight && key === _Keys.Keys.Left || key === _Keys.Keys.Tab && shiftKey) { | ||
if (focusManager.focusPrevious()) { | ||
var previous = focusManager.focusPrevious(); | ||
if (previous) { | ||
event.preventDefault(); | ||
if (onFocus) { | ||
onFocus(previous); | ||
} | ||
} | ||
@@ -62,5 +75,6 @@ } | ||
var child = typeof children === 'function' ? children(focusManager) : children; | ||
return /*#__PURE__*/_react.default.createElement(FocusConflictContext.Provider, { | ||
value: true | ||
}, /*#__PURE__*/_react.default.cloneElement(children, { | ||
}, /*#__PURE__*/_react.default.cloneElement(child, { | ||
onKeyDown: function onKeyDown(event) { | ||
@@ -73,4 +87,4 @@ if (hasParentFocus) { | ||
if (children.props.onKeyDown) { | ||
children.props.onKeyDown(event); | ||
if (child.props.onKeyDown) { | ||
child.props.onKeyDown(event); | ||
} | ||
@@ -83,3 +97,3 @@ | ||
elRef.current = r; | ||
var ref = children.ref; | ||
var ref = child.ref; | ||
@@ -86,0 +100,0 @@ if (ref) { |
{ | ||
"name": "@clayui/shared", | ||
"version": "3.67.0", | ||
"version": "3.69.0", | ||
"description": "ClayShared component", | ||
@@ -44,3 +44,3 @@ "license": "BSD-3-Clause", | ||
], | ||
"gitHead": "71e84490088d72afb0240a7ef69cde23a6d5dd19" | ||
"gitHead": "510da79d152edf887a1eed74d2d38787343ce6e4" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90962
2458