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

Lodash: Refactor components away from _.includes() #43518

Merged
merged 2 commits into from
Aug 23, 2022
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
5 changes: 5 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
- `Snackbar`: Refactor away from `_.omit()` ([#43474](https://github.com/WordPress/gutenberg/pull/43474/)).
- `UnitControl`: Refactor away from `_.omit()` ([#43474](https://github.com/WordPress/gutenberg/pull/43474/)).
- `BottomSheet`: Refactor away from `_.omit()` ([#43474](https://github.com/WordPress/gutenberg/pull/43474/)).
- `DropZone`: Refactor away from `_.includes()` ([#43518](https://github.com/WordPress/gutenberg/pull/43518/)).
- `NavigableMenu`: Refactor away from `_.includes()` ([#43518](https://github.com/WordPress/gutenberg/pull/43518/)).
- `Tooltip`: Refactor away from `_.includes()` ([#43518](https://github.com/WordPress/gutenberg/pull/43518/)).
- `TreeGrid`: Refactor away from `_.includes()` ([#43518](https://github.com/WordPress/gutenberg/pull/43518/)).


### Experimental
- `FormTokenField`: add `__experimentalAutoSelectFirstMatch` prop to auto select the first matching suggestion on typing ([#42527](https://github.com/WordPress/gutenberg/pull/42527/)).
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/drop-zone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { includes } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -60,12 +59,12 @@ export default function DropZoneComponent( {
* From Windows Chrome 96, the `event.dataTransfer` returns both file object and HTML.
* The order of the checks is important to recognise the HTML drop.
*/
if ( includes( event.dataTransfer.types, 'text/html' ) ) {
if ( event.dataTransfer.types.includes( 'text/html' ) ) {
_type = 'html';
} else if (
// Check for the types because sometimes the files themselves
// are only available on drop.
includes( event.dataTransfer.types, 'Files' ) ||
event.dataTransfer.types.includes( 'Files' ) ||
getFilesFromDataTransfer( event.dataTransfer ).length > 0
) {
_type = 'file';
Expand Down
10 changes: 3 additions & 7 deletions packages/components/src/navigable-container/menu.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// @ts-nocheck
/**
* External dependencies
*/
import { includes } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -35,11 +31,11 @@ export function NavigableMenu(
previous = [ LEFT, UP ];
}

if ( includes( next, keyCode ) ) {
if ( next.includes( keyCode ) ) {
return 1;
} else if ( includes( previous, keyCode ) ) {
} else if ( previous.includes( keyCode ) ) {
return -1;
} else if ( includes( [ DOWN, UP, LEFT, RIGHT ], keyCode ) ) {
} else if ( [ DOWN, UP, LEFT, RIGHT ].includes( keyCode ) ) {
// Key press should be handled, e.g. have event propagation and
// default behavior handled by NavigableContainer but not result
// in an offset.
Expand Down
6 changes: 1 addition & 5 deletions packages/components/src/tooltip/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// @ts-nocheck
/**
* External dependencies
*/
import { includes } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -211,7 +207,7 @@ function Tooltip( props ) {
// quickly blur/mouseleave before delayedSetIsOver is called.
delayedSetIsOver.cancel();

const _isOver = includes( [ 'focus', 'mouseenter' ], event.type );
const _isOver = [ 'focus', 'mouseenter' ].includes( event.type );
if ( _isOver === isOver ) {
return;
}
Expand Down
13 changes: 4 additions & 9 deletions packages/components/src/tree-grid/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { includes } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -68,7 +63,7 @@ function TreeGrid(

if (
hasModifierKeyPressed ||
! includes( [ UP, DOWN, LEFT, RIGHT, HOME, END ], keyCode )
! [ UP, DOWN, LEFT, RIGHT, HOME, END ].includes( keyCode )
) {
return;
}
Expand All @@ -92,7 +87,7 @@ function TreeGrid(
activeRow.getAttribute( 'aria-expanded' ) === 'false' &&
keyCode === RIGHT;

if ( includes( [ LEFT, RIGHT ], keyCode ) ) {
if ( [ LEFT, RIGHT ].includes( keyCode ) ) {
// Calculate to the next element.
let nextIndex;
if ( keyCode === LEFT ) {
Expand Down Expand Up @@ -177,7 +172,7 @@ function TreeGrid(
// Prevent key use for anything else. This ensures Voiceover
// doesn't try to handle key navigation.
event.preventDefault();
} else if ( includes( [ UP, DOWN ], keyCode ) ) {
} else if ( [ UP, DOWN ].includes( keyCode ) ) {
// Calculate the rowIndex of the next row.
const rows = Array.from(
treeGridElement.querySelectorAll( '[role="row"]' )
Expand Down Expand Up @@ -231,7 +226,7 @@ function TreeGrid(
// Prevent key use for anything else. This ensures Voiceover
// doesn't try to handle key navigation.
event.preventDefault();
} else if ( includes( [ HOME, END ], keyCode ) ) {
} else if ( [ HOME, END ].includes( keyCode ) ) {
// Calculate the rowIndex of the next row.
const rows = Array.from(
treeGridElement.querySelectorAll( '[role="row"]' )
Expand Down