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

fix(Dataspreadsheet): Reduce duplication with isHoldingCommandKey #4188 #4227

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 @@ -30,6 +30,7 @@ import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
import { getSpreadsheetWidth } from './utils/getSpreadsheetWidth';

import { useSpreadsheetMouseUp } from './hooks';
import { checkForHoldingKey } from './utils/checkForHoldingKey';

const blockClass = `${pkg.prefix}--data-spreadsheet`;

Expand Down Expand Up @@ -277,8 +278,8 @@ export const DataSpreadsheetBody = forwardRef(
`${blockClass}__body--td`
);
setValidStartingPoint(isValidSelectionAreaStart);
const isHoldingCommandKey = event.metaKey || event.ctrlKey;
const isHoldingShiftKey = event.shiftKey;
const isHoldingCommandKey = checkForHoldingKey(event, 'cmd');
const isHoldingShiftKey = checkForHoldingKey(event, 'shiftKey');
setContainerHasFocus(true);
const activeCoordinates = {
row: cell.row.index,
Expand Down Expand Up @@ -407,7 +408,7 @@ export const DataSpreadsheetBody = forwardRef(
const handleRowHeaderClick = useCallback(
(index) => {
return (event) => {
const isHoldingCommandKey = event.metaKey || event.ctrlKey;
const isHoldingCommandKey = checkForHoldingKey(event, 'cmd');
handleHeaderCellSelection({
type: 'row',
activeCellCoordinates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
import { selectAllCells } from './utils/selectAllCells';
import { getSpreadsheetWidth } from './utils/getSpreadsheetWidth';
import { useSpreadsheetMouseMove } from './hooks';
import { checkForHoldingKey } from './utils/checkForHoldingKey';

const blockClass = `${pkg.prefix}--data-spreadsheet`;

Expand Down Expand Up @@ -63,8 +64,8 @@ export const DataSpreadsheetHeader = forwardRef(

const handleColumnHeaderClick = (index) => {
return (event) => {
const isHoldingCommandKey = event.metaKey || event.ctrlKey;
const isHoldingShiftKey = event.shiftKey;
const isHoldingCommandKey = checkForHoldingKey(event, 'cmd');
const isHoldingShiftKey = checkForHoldingKey(event, 'shiftKey');
handleHeaderCellSelection({
type: 'column',
activeCellCoordinates,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright IBM Corp. 2022, 2022
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

export const checkForHoldingKey = (event, key) => {
// possible key inputs: altKey,ctrlKey,metaKey,shiftKey
if (key == 'cmd') {
return event.metaKey || event.ctrlKey;
} else {
return event[key];
}
};
Loading