-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix regression on keyboard navigation #61478
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
packages/dataviews/src/view-list.tsx
Outdated
@@ -40,7 +40,7 @@ interface ListViewProps { | |||
} | |||
|
|||
interface ListViewItemProps { | |||
id: string; | |||
id: any; |
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.
What's the proper type here?
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.
By reading the code it seems to be "string" but optional, so something like
id: any; | |
id?: string; |
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.
string | undefined
?
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'll add a bit of information, there's a subtle difference in what these two communicate:
// The property may not be present. If it is present it's a string
var x: { id?: string } = {};
var x2: { id?: string } = { id: undefined }; // TYPE ERROR!!
// The property _is_ present, `undefined` is an acceptable value. {} is not allowed here.
var y: { id: string | undefined } = { id: undefined };
var y2: { id: string | undefined } = {}; // TYPE ERROR!!
(Note that the x2
type error depends on exactOptionalPropertyTypes
which I don't think we have enabled in Gutenberg right now. It's relatively new but likely a good thing to enable.)
At runtime we often treat these as the same, but they're also subtly different depending on the type of check we're doing:
const x = {}
x.y; // undefined
Object.hasOwn(x, 'y'); // false
'y' in x; // false
x.y = undefined;
// The value is the same but the property is there:
x.y; // undefined
Object.hasOwn(x, 'y'); // true
'y' in x; // true
We should think about adding some more e2e tests for data views (keyboard navigation being one of them) |
Co-authored-by: Riad Benguella <benguella@gmail.com>
What?
This PR fixes a regression on keyboard navigation for the list layout (dataviews) by which the list items weren't reachable via TAB.
Gravacao.do.ecra.2024-05-08.as.10.56.29.mov
How?
The result of
getItemDomId
needs to be undefined if there's no item.Testing Instructions