Skip to content

Commit

Permalink
Make the useDisabled hook stable (#40890)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored May 9, 2022
1 parent 3065308 commit 2c5b236
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
__unstableGetBlockProps as getBlockProps,
getBlockType,
} from '@wordpress/blocks';
import {
useMergeRefs,
__experimentalUseDisabled as useIsDisabled,
} from '@wordpress/compose';
import { useMergeRefs, useDisabled } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import warning from '@wordpress/warning';

Expand Down Expand Up @@ -132,7 +129,7 @@ export function useBlockProps(
enableAnimation,
triggerAnimationOnChange: index,
} ),
useIsDisabled( { isDisabled: ! __unstableIsDisabled } ),
useDisabled( { isDisabled: ! __unstableIsDisabled } ),
] );

const blockEditContext = useBlockEditContext();
Expand Down
5 changes: 1 addition & 4 deletions packages/block-editor/src/components/block-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
__experimentalUseDisabled as useDisabled,
useMergeRefs,
} from '@wordpress/compose';
import { useDisabled, useMergeRefs } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
import { memo, useMemo } from '@wordpress/element';

Expand Down
5 changes: 1 addition & 4 deletions packages/block-library/src/post-comments-form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import {
__experimentalUseDisabled as useDisabled,
useInstanceId,
} from '@wordpress/compose';
import { useDisabled, useInstanceId } from '@wordpress/compose';

const CommentsForm = () => {
const disabledFormRef = useDisabled();
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/post-comments/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { __, sprintf } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useEntityProp, store as coreStore } from '@wordpress/core-data';
import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
import { useDisabled } from '@wordpress/compose';
import { createInterpolateElement } from '@wordpress/element';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/table-of-contents/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ToolbarButton,
ToolbarGroup,
} from '@wordpress/components';
import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
import { useDisabled } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { __unstableStripHTML as stripHTML } from '@wordpress/dom';
import { renderToString, useEffect } from '@wordpress/element';
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/disabled/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
import { useDisabled } from '@wordpress/compose';
import { createContext } from '@wordpress/element';

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/compose/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- `useRefEffect`: Allow `void` as a valid callback return type ([#40798](https://github.com/WordPress/gutenberg/pull/40798)).

### New Features

- Add `useDisabled` hook.

## 5.6.0 (2022-05-04)

## 5.5.0 (2022-04-21)
Expand Down
33 changes: 33 additions & 0 deletions packages/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,39 @@ _Returns_

- `import('lodash').DebouncedFunc<TFunc>`: Debounced function.

### useDisabled

In some circumstances, such as block previews, all focusable DOM elements
(input fields, links, buttons, etc.) need to be disabled. This hook adds the
behavior to disable nested DOM elements to the returned ref.

_Usage_

```js
import { useDisabled } from '@wordpress/compose';
const DisabledExample = () => {
const disabledRef = useDisabled();
return (
<div ref={ disabledRef }>
<a href="#">This link will have tabindex set to -1</a>
<input
placeholder="This input will have the disabled attribute added to it."
type="text"
/>
</div>
);
};
```

_Parameters_

- _config_ `Object`: Configuration object.
- _config.isDisabled_ `boolean=`: Whether the element should be disabled.

_Returns_

- `import('react').RefCallback<HTMLElement>`: Element Ref.

### useFocusableIframe

Dispatches a bubbling focus event when the iframe receives focus. Use
Expand Down
2 changes: 1 addition & 1 deletion packages/compose/src/hooks/use-disabled/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const DISABLED_ELIGIBLE_NODE_NAMES = [
*
* @example
* ```js
* import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
* import { useDisabled } from '@wordpress/compose';
* const DisabledExample = () => {
* const disabledRef = useDisabled();
* return (
Expand Down
2 changes: 1 addition & 1 deletion packages/compose/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export { default as useConstrainedTabbing } from './hooks/use-constrained-tabbin
export { default as useCopyOnClick } from './hooks/use-copy-on-click';
export { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';
export { default as __experimentalUseDialog } from './hooks/use-dialog';
export { default as __experimentalUseDisabled } from './hooks/use-disabled';
export { default as useDisabled } from './hooks/use-disabled';
export { default as __experimentalUseDragging } from './hooks/use-dragging';
export { default as useFocusOnMount } from './hooks/use-focus-on-mount';
export { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';
Expand Down

0 comments on commit 2c5b236

Please sign in to comment.