Skip to content
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

Merged
merged 2 commits into from
May 8, 2024

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented May 8, 2024

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

  • Visit Site Editor > Pages.
  • Try to reach the list items via keyboard navigation (TAB).

Copy link

github-actions bot commented May 8, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@oandregal oandregal requested review from youknowriad and sirreal May 8, 2024 08:59
@oandregal oandregal self-assigned this May 8, 2024
@oandregal oandregal added [Type] Regression Related to a regression in the latest release [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels May 8, 2024
@@ -40,7 +40,7 @@ interface ListViewProps {
}

interface ListViewItemProps {
id: string;
id: any;
Copy link
Member Author

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?

Copy link
Contributor

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

Suggested change
id: any;
id?: string;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string | undefined?

Copy link
Member

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

@youknowriad
Copy link
Contributor

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>
@oandregal oandregal enabled auto-merge (squash) May 8, 2024 10:13
@oandregal oandregal merged commit 4ae0dca into trunk May 8, 2024
62 checks passed
@oandregal oandregal deleted the fix/list-layout-keyboard-navigation branch May 8, 2024 10:13
@github-actions github-actions bot added this to the Gutenberg 18.4 milestone May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants