Fix problem with focus
This commit is contained in:
parent
686acabd9f
commit
fc9a0941db
@ -14,6 +14,7 @@ function ViewportPane({
|
|||||||
onInteraction,
|
onInteraction,
|
||||||
acceptDropsFor,
|
acceptDropsFor,
|
||||||
}) {
|
}) {
|
||||||
|
let dropElement = null;
|
||||||
const [{ isHovered, isHighlighted }, drop] = useDrop({
|
const [{ isHovered, isHighlighted }, drop] = useDrop({
|
||||||
accept: acceptDropsFor,
|
accept: acceptDropsFor,
|
||||||
// TODO: pass in as prop?
|
// TODO: pass in as prop?
|
||||||
@ -22,7 +23,7 @@ function ViewportPane({
|
|||||||
const isOver = monitor.isOver();
|
const isOver = monitor.isOver();
|
||||||
|
|
||||||
if (canDrop && isOver && onDrop) {
|
if (canDrop && isOver && onDrop) {
|
||||||
onInteraction();
|
onInteractionHandler();
|
||||||
onDrop(droppedItem);
|
onDrop(droppedItem);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -33,16 +34,32 @@ function ViewportPane({
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const focus = () => {
|
||||||
|
if (dropElement) {
|
||||||
|
dropElement.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onInteractionHandler = () => {
|
||||||
|
onInteraction();
|
||||||
|
focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
const refHandler = element => {
|
||||||
|
drop(element);
|
||||||
|
dropElement = element;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={drop}
|
ref={refHandler}
|
||||||
// onInteraction...
|
// onInteractionHandler...
|
||||||
// https://reactjs.org/docs/events.html#mouse-events
|
// https://reactjs.org/docs/events.html#mouse-events
|
||||||
// https://stackoverflow.com/questions/8378243/catch-scrolling-event-on-overflowhidden-element
|
// https://stackoverflow.com/questions/8378243/catch-scrolling-event-on-overflowhidden-element
|
||||||
onMouseDown={onInteraction}
|
onMouseDown={onInteractionHandler}
|
||||||
onClick={onInteraction}
|
onClick={onInteractionHandler}
|
||||||
onScroll={onInteraction}
|
onScroll={onInteractionHandler}
|
||||||
onWheel={onInteraction}
|
onWheel={onInteractionHandler}
|
||||||
className={classnames(
|
className={classnames(
|
||||||
'flex flex-col',
|
'flex flex-col',
|
||||||
'rounded-lg hover:border-primary-light transition duration-300 outline-none overflow-hidden',
|
'rounded-lg hover:border-primary-light transition duration-300 outline-none overflow-hidden',
|
||||||
@ -73,7 +90,7 @@ ViewportPane.propTypes = {
|
|||||||
onInteraction: PropTypes.func.isRequired,
|
onInteraction: PropTypes.func.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
const noop = () => {};
|
const noop = () => { };
|
||||||
|
|
||||||
ViewportPane.defaultProps = {
|
ViewportPane.defaultProps = {
|
||||||
onInteraction: noop,
|
onInteraction: noop,
|
||||||
|
|||||||
@ -115,15 +115,17 @@ function ViewerViewportGrid(props) {
|
|||||||
viewportComponents
|
viewportComponents
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onInterationHandler = () => {
|
||||||
|
setActiveViewportIndex(viewportIndex);
|
||||||
|
};
|
||||||
|
|
||||||
viewportPanes[i] = (
|
viewportPanes[i] = (
|
||||||
<ViewportPane
|
<ViewportPane
|
||||||
key={viewportIndex}
|
key={viewportIndex}
|
||||||
className="m-1"
|
className="m-1"
|
||||||
acceptDropsFor="displayset"
|
acceptDropsFor="displayset"
|
||||||
onDrop={onDropHandler.bind(null, viewportIndex)}
|
onDrop={onDropHandler.bind(null, viewportIndex)}
|
||||||
onInteraction={() => {
|
onInteraction={onInterationHandler}
|
||||||
setActiveViewportIndex(viewportIndex);
|
|
||||||
}}
|
|
||||||
isActive={activeViewportIndex === viewportIndex}
|
isActive={activeViewportIndex === viewportIndex}
|
||||||
>
|
>
|
||||||
<ViewportComponent
|
<ViewportComponent
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user