setMouseDown( true ) }
+ onTouchMove={ handleChange }
+ onTouchStart={ handleChange }
+ role="application"
+ >
+
+
+
+
-
-
-
-
- { __(
- 'Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.'
- ) }
-
-
-
- );
- /* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
- }
+ { __(
+ 'Use your arrow keys to change the base color. Move up to lighten the color, down to darken, left to decrease saturation, and right to increase saturation.'
+ ) }
+
+
+
+ );
+ /* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
}
-
-export default compose( pure, withInstanceId )( Saturation );
diff --git a/packages/components/src/color-picker/test/index.js b/packages/components/src/color-picker/test/index.js
index 11244c8a27e67a..866f1f73634d46 100644
--- a/packages/components/src/color-picker/test/index.js
+++ b/packages/components/src/color-picker/test/index.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
-import TestRenderer from 'react-test-renderer';
+import { create, act } from 'react-test-renderer';
/**
* WordPress dependencies
@@ -13,106 +13,183 @@ import { DOWN, ENTER, UP } from '@wordpress/keycodes';
*/
import ColorPicker from '../';
+function createNodeMock( element ) {
+ if (
+ element.type === 'div' &&
+ [
+ 'components-color-picker__alpha-bar',
+ 'components-color-picker__hue-bar',
+ 'components-color-picker__saturation-color',
+ ].includes( element.props.className )
+ ) {
+ return {
+ ownerDocument: document,
+ };
+ }
+
+ return null;
+}
+
describe( 'ColorPicker', () => {
- const color = '#FFF';
- let base;
-
- beforeEach( () => {
- base = TestRenderer.create(
- {} }
- disableAlpha
- />
- );
- } );
+ test( 'should render color picker', () => {
+ const color = '#FFF';
+ let renderer;
+
+ act( () => {
+ renderer = create(
+ {} }
+ disableAlpha
+ />,
+ { createNodeMock }
+ );
+ } );
+ });
test( 'should render color picker', () => {
expect( base.toJSON() ).toMatchSnapshot();
} );
test( 'should only update input view for draft changes', () => {
- const testRenderer = TestRenderer.create(
- {} }
- disableAlpha
- />
- );
- testRenderer.root
- .findByType( 'input' )
- .props.onChange( { target: { value: '#ABC' } } );
-
- expect( testRenderer.toJSON() ).toMatchDiffSnapshot( base.toJSON() );
+ const color = '#FFF';
+ let testRenderer;
+
+ act( () => {
+ testRenderer = create(
+ {} }
+ disableAlpha
+ />,
+ { createNodeMock }
+ );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onChange( { target: { value: '#ABC' } } );
+ } );
+
+ expect( testRenderer.toJSON() ).toMatchSnapshot();
} );
test( 'should commit changes to all views on blur', () => {
- const testRenderer = TestRenderer.create(
- {} }
- disableAlpha
- />
- );
- testRenderer.root
- .findByType( 'input' )
- .props.onChange( { target: { value: '#ABC' } } );
- testRenderer.root.findByType( 'input' ).props.onBlur();
-
- expect( testRenderer.toJSON() ).toMatchDiffSnapshot( base.toJSON() );
+ const color = '#FFF';
+ let testRenderer;
+
+ act( () => {
+ testRenderer = create(
+ {} }
+ disableAlpha
+ />,
+ { createNodeMock }
+ );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onChange( { target: { value: '#ABC' } } );
+ } );
+
+ act( () => {
+ testRenderer.root.findByType( 'input' ).props.onBlur();
+ } );
+
+ expect( testRenderer.toJSON() ).toMatchSnapshot();
} );
test( 'should commit changes to all views on keyDown = UP', () => {
- const testRenderer = TestRenderer.create(
- {} }
- disableAlpha
- />
- );
- testRenderer.root
- .findByType( 'input' )
- .props.onChange( { target: { value: '#ABC' } } );
- testRenderer.root
- .findByType( 'input' )
- .props.onKeyDown( { keyCode: UP } );
-
- expect( testRenderer.toJSON() ).toMatchDiffSnapshot( base.toJSON() );
+ const color = '#FFF';
+ let testRenderer;
+
+ act( () => {
+ testRenderer = create(
+ {} }
+ disableAlpha
+ />,
+ { createNodeMock }
+ );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onChange( { target: { value: '#ABC' } } );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onKeyDown( { keyCode: UP } );
+ } );
+
+ expect( testRenderer.toJSON() ).toMatchSnapshot();
} );
test( 'should commit changes to all views on keyDown = DOWN', () => {
- const testRenderer = TestRenderer.create(
- {} }
- disableAlpha
- />
- );
- testRenderer.root
- .findByType( 'input' )
- .props.onChange( { target: { value: '#ABC' } } );
- testRenderer.root
- .findByType( 'input' )
- .props.onKeyDown( { keyCode: DOWN } );
-
- expect( testRenderer.toJSON() ).toMatchDiffSnapshot( base.toJSON() );
+ const color = '#FFF';
+ let testRenderer;
+
+ act( () => {
+ testRenderer = create(
+ {} }
+ disableAlpha
+ />,
+ { createNodeMock }
+ );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onChange( { target: { value: '#ABC' } } );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onKeyDown( { keyCode: DOWN } );
+ } );
+
+ expect( testRenderer.toJSON() ).toMatchSnapshot();
} );
test( 'should commit changes to all views on keyDown = ENTER', () => {
- const testRenderer = TestRenderer.create(
- {} }
- disableAlpha
- />
- );
- testRenderer.root
- .findByType( 'input' )
- .props.onChange( { target: { value: '#ABC' } } );
- testRenderer.root
- .findByType( 'input' )
- .props.onKeyDown( { keyCode: ENTER } );
-
- expect( testRenderer.toJSON() ).toMatchDiffSnapshot( base.toJSON() );
+ const color = '#FFF';
+ let testRenderer;
+
+ act( () => {
+ testRenderer = create(
+ {} }
+ disableAlpha
+ />,
+ { createNodeMock }
+ );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onChange( { target: { value: '#ABC' } } );
+ } );
+
+ act( () => {
+ testRenderer.root
+ .findByType( 'input' )
+ .props.onKeyDown( { keyCode: ENTER } );
+ } );
+
+ expect( testRenderer.toJSON() ).toMatchSnapshot();
} );
} );
diff --git a/packages/compose/README.md b/packages/compose/README.md
index a5d36e2bae5ee8..d38b7a9b7546ea 100644
--- a/packages/compose/README.md
+++ b/packages/compose/README.md
@@ -391,7 +391,7 @@ _Returns_
# **useThrottle**
-Throttles a function with Lodash's `throttle`. A new throttled function will
+Throttle a function with Lodash's `throttle`. A new throttled function will
be returned and any scheduled calls cancelled if any of the arguments change,
including the function to throttle, so please wrap functions created on
render in components in `useCallback`.
@@ -402,7 +402,7 @@ _Parameters_
_Returns_
-- `Function`: Throttled function.
+- `Function`: returns the throttled function
# **useViewportMatch**
diff --git a/packages/compose/src/hooks/use-throttle/index.js b/packages/compose/src/hooks/use-throttle/index.js
index e6436424d71212..5ce2d1d04b8eb7 100644
--- a/packages/compose/src/hooks/use-throttle/index.js
+++ b/packages/compose/src/hooks/use-throttle/index.js
@@ -10,14 +10,14 @@ import { useMemoOne } from 'use-memo-one';
import { useEffect } from '@wordpress/element';
/**
- * Throttles a function with Lodash's `throttle`. A new throttled function will
+ * Throttle a function with Lodash's `throttle`. A new throttled function will
* be returned and any scheduled calls cancelled if any of the arguments change,
* including the function to throttle, so please wrap functions created on
* render in components in `useCallback`.
*
* @param {...any} args Arguments passed to Lodash's `throttle`.
*
- * @return {Function} Throttled function.
+ * @return {Function} returns the throttled function
*/
export default function useThrottle( ...args ) {
const throttled = useMemoOne( () => throttle( ...args ), args );
diff --git a/packages/compose/src/index.native.js b/packages/compose/src/index.native.js
index 2471f9d27a45b8..a954f064f748d5 100644
--- a/packages/compose/src/index.native.js
+++ b/packages/compose/src/index.native.js
@@ -29,3 +29,4 @@ export { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-c
export { default as useResizeObserver } from './hooks/use-resize-observer';
export { default as useDebounce } from './hooks/use-debounce';
export { default as useMergeRefs } from './hooks/use-merge-refs';
+export { default as useThrottle } from './hooks/use-throttle';