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

[DataGrid] Fix multiple focus behaviors #1421

Merged
merged 17 commits into from
Apr 28, 2021
Merged

Conversation

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

This breaks the roving index, cc @DanailH.

I think that we absolutely need tests for the tab and focus behavior, it's brittle and easy to break.

@dtassone
Copy link
Member Author

This breaks the roving index, cc @DanailH.

I think that we absolutely need tests for the tab and focus behavior, it's brittle and easy to break.

I can do tests but why is the roving index broken?

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 16, 2021

I can do tests but why is the roving index broken?

@dtassone One example of regression:

roving index

https://deploy-preview-1421--material-ui-x.netlify.app/components/data-grid/#mit-version

@@ -149,6 +153,10 @@ export const GridColumnHeaderItem = ({
}
});

const isFirstTabbable =
Copy link
Member

@DanailH DanailH Apr 16, 2021

Choose a reason for hiding this comment

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

I'm not sure that the first column header should be tabbable. I was left with the impression that the first cell should be tabbable.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the thing, IMO, the first tabbable control of a sortable grid should be the first sortable column header
https://www.w3.org/TR/wai-aria-practices/examples/grid/dataGrids.html

So in our case, I put the first column so we could argue that if none of the columns have an action then it should be the first cell of the first row

Copy link
Member

Choose a reason for hiding this comment

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

Actually, if we use that logic then the first tabbable cell should be either the column header that is sortable or the one that has a column menu as it is also a interaction.

@dtassone
Copy link
Member Author

split cell focus state and tabindex state
so when tab leave grid we can focus back on the previously focused element

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 19, 2021

fix #1420 (not sure about 2.)

I meant that the rating is a radio group, that should handle arrow keys.

rating

@DanailH
Copy link
Member

DanailH commented Apr 19, 2021

This breaks the roving index, cc @DanailH.

I think that we absolutely need tests for the tab and focus behavior, it's brittle and easy to break.

It's on my radar. I'll work on it today.

@DanailH
Copy link
Member

DanailH commented Apr 20, 2021

This breaks the roving index, cc @DanailH.
I think that we absolutely need tests for the tab and focus behavior, it's brittle and easy to break.

It's on my radar. I'll work on it today.

Here is the PR with the e2e setup #1443

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

Comment on lines +72 to +74
keyboard: { isMultipleKeyPressed: false },
focus: { cell: null, columnHeader: null },
tabIndex: { cell: null, columnHeader: null },
Copy link
Member

Choose a reason for hiding this comment

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

This looks better. We should soon be able to kill keyboard with #1437 from @m4theushw.
I would also advocate to kill focus but it will be for another discussion.

const inputs = document.querySelectorAll('input');
expect(inputs.length).to.equal(2);
const nikeInput = getCell(0, 0).querySelector('input');
fireEvent.click(nikeInput);
Copy link
Member Author

Choose a reason for hiding this comment

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

@oliviertassinari any idea why this test does not work?

Copy link
Member

Choose a reason for hiding this comment

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

Could we simplify the test case (remove most of the code)? It doesn't seem that we need all this to create a failing test case.

Copy link
Member

Choose a reason for hiding this comment

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

As for why the test case doesn't work. I recall that your first commit was to add a blur listener to fix the issue, so if you don't handle the activeElement, I don't see how the test could work, e.g. calling .focus(). We are inside a browser, fire event click doesn't trigger all the intermediary event (mouse down/mouse up/focus) that a real browse have. You have to simulate them.

@DanailH
Copy link
Member

DanailH commented Apr 22, 2021

Ok I think I found a bug but I'm struggling to make i video of it I'll try and list the steps:

  • Tab until you focus the first grid cell
  • Press the right arrow key until you reach the last cell in the row
  • Press the right arrow key one more time
  • Tab again to move out of the grid
  • Shift + Tab to move back into the grid. It doesn't select the grid bug skips it and selects the tabbable element before the grid.

@dtassone if you want to ping me and I will show you the problem if you cant reproduce it.

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

The fix seems to work and I can't spot a regression 👍 . I'm adding test cases for the one we found #1459.

const inputs = document.querySelectorAll('input');
expect(inputs.length).to.equal(2);
const nikeInput = getCell(0, 0).querySelector('input');
fireEvent.click(nikeInput);
Copy link
Member

Choose a reason for hiding this comment

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

Could we simplify the test case (remove most of the code)? It doesn't seem that we need all this to create a failing test case.

const inputs = document.querySelectorAll('input');
expect(inputs.length).to.equal(2);
const nikeInput = getCell(0, 0).querySelector('input');
fireEvent.click(nikeInput);
Copy link
Member

Choose a reason for hiding this comment

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

As for why the test case doesn't work. I recall that your first commit was to add a blur listener to fix the issue, so if you don't handle the activeElement, I don't see how the test could work, e.g. calling .focus(). We are inside a browser, fire event click doesn't trigger all the intermediary event (mouse down/mouse up/focus) that a real browse have. You have to simulate them.

@dtassone
Copy link
Member Author

I thought it would fire focus on click with fireevent
https://testing-library.com/docs/guide-events/

If I simulate the event then the test doesn't fail without the fix

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 24, 2021

  • @dtassone you need to rebase, as you are changing the behavior of existing tests that are on HEAD but not on your baseline commit of this PR
  • I have updated the PR's description to be more accurate on the issues that are fixed
  • Could we add test cases for each individual bug we bundled together in this PR?

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

I didn't look closely in the logic, @m4theushw interested in having a closer look?

I didn't see a test case for the change of focused element for the checkboxes @dtassone what do you think about adding a regulae jsdom/Karma test to cover the new behavior?

@dtassone dtassone merged commit fda80d8 into mui:master Apr 28, 2021
@oliviertassinari oliviertassinari changed the title [DataGrid] refactoring on focus cell and cols [DataGrid] Fix multiple focus behaviors Apr 28, 2021
@oliviertassinari
Copy link
Member

I have updated the title so developers can understand the problem solved by this PR once it's displayed in the changelog. Also notice the capitalization so it behaves like a full sentence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
4 participants