Skip to content

Commit

Permalink
useFocusableIframe: Refactor to TypeScript (#45428)
Browse files Browse the repository at this point in the history
* `useFocusableIframe`: Refactor to TypeScript

* Update CHANGELOG.md

* Add return type
  • Loading branch information
Petter Walbø Johnsgård authored Nov 1, 2022
1 parent 5068af4 commit 3e7a5e9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 0 additions & 1 deletion packages/components/src/focusable-iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import deprecated from '@wordpress/deprecated';
* @param {import('react').Ref<HTMLIFrameElement>} props.iframeRef
*/
export default function FocusableIframe( { iframeRef, ...props } ) {
// @ts-expect-error: Return type for useFocusableIframe() is incorrect.
const ref = useMergeRefs( [ iframeRef, useFocusableIframe() ] );
deprecated( 'wp.components.FocusableIframe', {
since: '5.9',
Expand Down
1 change: 1 addition & 0 deletions packages/compose/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- `useDisabled`: Refactor the component to rely on the HTML `inert` attribute ([#44865](https://github.com/WordPress/gutenberg/pull/44865)).
- `useFocusOutside`: Refactor the hook to TypeScript, rewrite tests using modern RTL and jest features ([#45317](https://github.com/WordPress/gutenberg/pull/45317)).
- `useFocusableIframe`: Refactor to TypeScript ([#45428](https://github.com/WordPress/gutenberg/pull/45428)).

## 5.18.0 (2022-10-19)

Expand Down
2 changes: 1 addition & 1 deletion packages/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ Dispatches a bubbling focus event when the iframe receives focus. Use

_Returns_

- `Object`: Ref to pass to the iframe.
- `RefCallback< HTMLIFrameElement >`: Ref to pass to the iframe.

### useFocusOnMount

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import type { RefCallback } from 'react';

/**
* Internal dependencies
*/
Expand All @@ -7,9 +12,9 @@ import useRefEffect from '../use-ref-effect';
* Dispatches a bubbling focus event when the iframe receives focus. Use
* `onFocus` as usual on the iframe or a parent element.
*
* @return {Object} Ref to pass to the iframe.
* @return Ref to pass to the iframe.
*/
export default function useFocusableIframe() {
export default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {
return useRefEffect( ( element ) => {
const { ownerDocument } = element;
if ( ! ownerDocument ) return;
Expand All @@ -22,7 +27,7 @@ export default function useFocusableIframe() {
*/
function checkFocus() {
if ( ownerDocument && ownerDocument.activeElement === element ) {
/** @type {HTMLElement} */ ( element ).focus();
( element as HTMLElement ).focus();
}
}

Expand Down

0 comments on commit 3e7a5e9

Please sign in to comment.