mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-06 03:45:18 +00:00
@@ -91,6 +91,25 @@ describe('components/Pressable', () => {
|
|||||||
expect(container.firstChild).toMatchSnapshot();
|
expect(container.firstChild).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('focus interaction (disabled)', () => {
|
||||||
|
const onBlur = jest.fn();
|
||||||
|
const onFocus = jest.fn();
|
||||||
|
const ref = React.createRef();
|
||||||
|
act(() => {
|
||||||
|
render(<Pressable disabled={true} onBlur={onBlur} onFocus={onFocus} ref={ref} />);
|
||||||
|
});
|
||||||
|
const target = createEventTarget(ref.current);
|
||||||
|
const body = createEventTarget(document.body);
|
||||||
|
act(() => {
|
||||||
|
target.focus();
|
||||||
|
});
|
||||||
|
expect(onFocus).not.toBeCalled();
|
||||||
|
act(() => {
|
||||||
|
body.focus({ relatedTarget: target.node });
|
||||||
|
});
|
||||||
|
expect(onBlur).not.toBeCalled();
|
||||||
|
});
|
||||||
|
|
||||||
test('hover interaction', () => {
|
test('hover interaction', () => {
|
||||||
let container;
|
let container;
|
||||||
const onHoverIn = jest.fn();
|
const onHoverIn = jest.fn();
|
||||||
|
|||||||
@@ -144,6 +144,9 @@ function Pressable(props: Props, forwardedRef): React.Node {
|
|||||||
|
|
||||||
const blurHandler = React.useCallback(
|
const blurHandler = React.useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (e.nativeEvent.target === hostRef.current) {
|
if (e.nativeEvent.target === hostRef.current) {
|
||||||
setFocused(false);
|
setFocused(false);
|
||||||
if (onBlur != null) {
|
if (onBlur != null) {
|
||||||
@@ -151,11 +154,14 @@ function Pressable(props: Props, forwardedRef): React.Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[hostRef, setFocused, onBlur]
|
[disabled, hostRef, setFocused, onBlur]
|
||||||
);
|
);
|
||||||
|
|
||||||
const focusHandler = React.useCallback(
|
const focusHandler = React.useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (e.nativeEvent.target === hostRef.current) {
|
if (e.nativeEvent.target === hostRef.current) {
|
||||||
setFocused(true);
|
setFocused(true);
|
||||||
if (onFocus != null) {
|
if (onFocus != null) {
|
||||||
@@ -163,7 +169,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[hostRef, setFocused, onFocus]
|
[disabled, hostRef, setFocused, onFocus]
|
||||||
);
|
);
|
||||||
|
|
||||||
const contextMenuHandler = React.useCallback(
|
const contextMenuHandler = React.useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user