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
Update some React 18 related types #45279
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
89049f5
IsolatedEventContainer: ensure there is type for children
jsnajdr 04407b9
FormFileUpload: fix render() call because void is not assignable to u…
jsnajdr a18b467
ToggleControl: enhance help prop type to allow functions
jsnajdr 2c8b79f
Popover: add types to arrowRef
jsnajdr 6a0f4a8
useFocusOutside: use param type annotation closer to the actual function
jsnajdr b7b5064
useDialog: specify type for event listener, use DOM KeyboardEvent type
jsnajdr 4a0e4f6
ToggleControl fix: show dynamic help label only for controlled compon…
jsnajdr 233bd8e
FormFileUpload: fix the render prop type and behavior
jsnajdr fb0086d
ToggleControl: add changelog entry and update docs
jsnajdr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
packages/components/src/isolated-event-container/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentPropsWithoutRef, MouseEvent } from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { forwardRef } from '@wordpress/element'; | ||
import deprecated from '@wordpress/deprecated'; | ||
|
||
function stopPropagation( event: MouseEvent ) { | ||
event.stopPropagation(); | ||
} | ||
|
||
type DivProps = ComponentPropsWithoutRef< 'div' >; | ||
|
||
const IsolatedEventContainer = forwardRef< HTMLDivElement, DivProps >( | ||
( props, ref ) => { | ||
deprecated( 'wp.components.IsolatedEventContainer', { | ||
since: '5.7', | ||
} ); | ||
|
||
// Disable reason: this stops certain events from propagating outside of the component. | ||
// - onMouseDown is disabled as this can cause interactions with other DOM elements. | ||
/* eslint-disable jsx-a11y/no-static-element-interactions */ | ||
return <div { ...props } ref={ ref } onMouseDown={ stopPropagation } />; | ||
/* eslint-enable jsx-a11y/no-static-element-interactions */ | ||
} | ||
); | ||
|
||
export default IsolatedEventContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would make sense to allow
help
to be called with anundefined
, as it currently is ontrunk
. The docs don't mention anything abouthelp
working only for controlled componentsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an entry about the
ToggleControl
'shelp
prop type. Other changes in this PR are not publicly visible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an incorrect behavior though. If the
checked
prop is not specified, then theinput
in uncontrolled, i.e., it stores thechecked
state internally and only fires theonChange
events. The user can check the toggle, it will fire theonChange
event, will be checked visually, but thechecked
prop variable will still beundefined
. The wronghelp
will be shown.After a closer look, I see that
ToggleControl
doesn't really support uncontrolled mode correctly. A checkedFormToggle
component won't have theis-checked
CSS class, because thechecked
prop is nevertrue
. Also the component doesn't have adefaultChecked
prop for setting initial uncontrolled value.The
checked
value shouldn't be allowed to beundefined
. It only creates an illusion of supporting uncontrolled mode, but the support is not really there. And all usages in the Gutenberg codebase seem to be controlled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you again for looking into this! Your reasoning makes sense to me.
That seems to be an issue most of the older control components in the library, thank you for flagging