Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove the never used 'when' prop in KeyboardZone to avoid rerendering #2000

Merged
merged 4 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const KeyNameByModifierAttr = {
const overriddenKeyCodes = ['Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];

interface KeyboardZoneProps {
when: string;
onCommand: (action, e: KeyboardEvent) => object | void;
}

Expand All @@ -35,7 +34,7 @@ const buildModifierKeyPrefix = (e: KeyboardEvent): string => {
return prefix;
};

export const KeyboardZone: FC<KeyboardZoneProps> = ({ when, onCommand, children }): JSX.Element => {
export const KeyboardZone: FC<KeyboardZoneProps> = ({ onCommand, children }): JSX.Element => {
const handleKeyDown = e => {
if (overriddenKeyCodes.includes(e.key)) {
e.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,7 @@ export const ObiEditor: FC<ObiEditorProps> = ({
selectedIds: [],
});

const [keyboardStatus, setKeyBoardStatus] = useState('normal');

useEffect((): void => {
if (selectionContext.selectedIds.length > 0) {
setKeyBoardStatus('selected');
} else if (focusedId) {
setKeyBoardStatus('focused');
} else {
setKeyBoardStatus('normal');
}

// Notify container at every selection change.
onSelect(selectionContext.selectedIds.length ? selectionContext.selectedIds : focusedId ? [focusedId] : []);
}, [focusedId, selectionContext]);
Expand Down Expand Up @@ -296,7 +286,7 @@ export const ObiEditor: FC<ObiEditorProps> = ({
if (!data) return renderFallbackContent();
return (
<SelectionContext.Provider value={selectionContext}>
<KeyboardZone onCommand={handleKeyboardCommand} when={keyboardStatus}>
<KeyboardZone onCommand={handleKeyboardCommand}>
<MarqueeSelection selection={selection} css={{ width: '100%', height: '100%' }}>
<div
tabIndex={0}
Expand Down