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 focus cell visibility #256

Merged
merged 1 commit into from
Sep 10, 2020
Merged

Conversation

dtassone
Copy link
Member

@dtassone dtassone commented Sep 9, 2020

Fix #254

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.

Should we add a test cases to avoid regressions in the future? Any idea on how we could best write them? For instance, with karma we could call .getBoundingClientRect() and make sure the horizontal offset is correct. It should be easy to write, fast to run and easy to debug if there is a regression (hopefully). I think that we could also argue that puppeteer would make it even easier to debug (in case of a regression), however, we would first need to:

  • add puppeteer in the CI, otherwise the test has no value
  • figure out why the tests are slow to run, I suspect moving from storybook to next.js to run them will help a lot but I have no data to back this (only an intuition that by using code spliting, we will save a lot of time both during runtime in the CI and locally.

I think that we should avoid visual tests for this type of problems, it would be slower to run and less accurate in the assertion.

@@ -65,7 +65,7 @@ export const useVirtualColumns = (
const lastCol = getColumnFromScroll(lastScrollLeftRef.current + windowWidth);

const visibleColumns = apiRef.current.getVisibleColumns();
const firstColIndex = visibleColumns.findIndex((col) => col.field === firstCol?.field);
const firstColIndex = visibleColumns.findIndex((col) => col.field === firstCol?.field) + 1;
Copy link
Member

Choose a reason for hiding this comment

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

Is the name firstColIndex still accurate?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that we should avoid visual tests for this type of problems, it would be slower to run and less accurate in the assertion.

Well you will need to check the scroll and calculate that the scrollLeft value is less than the offset value of the focused cell by a small amount. Also you will need to press arrow left a few times until the focus move to a cell well outside the viewport. Then go back to the first column....
For me, it's the kind of test that will be very difficult to understand and visualize in karma.

Copy link
Member

@oliviertassinari oliviertassinari Sep 10, 2020

Choose a reason for hiding this comment

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

Well you will need to check the scroll and calculate that the scrollLeft

I think that we can only call getBoundingClientRect and make sure .left === 0, I don't see the need to test scroll or only other value. Yes, the test would need to use the keyboard to get into the right condition. This sounds perfect, reproducing the real-life use case.

Regarding the pain to visualize in Karma, I agree with you. It's why I said: "I think that we could also argue that puppeteer would make it even easier to debug". Puppeteer has more potential for this type of visual issue, but it's yet to be untapped by making it something we can rely on (it's not the case yet because it's no integrated in the CI).

Copy link
Member

@oliviertassinari oliviertassinari Sep 10, 2020

Choose a reason for hiding this comment

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

Well, document.activeElement.getBoundingClientRect().left === 0 would work only if we remove the body margin, a quick POC:

Capture d’écran 2020-09-10 à 12 12 07

it displays -5, which is KO.

Copy link
Member Author

Choose a reason for hiding this comment

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

Testing the component within the doc is probably not the best. As the doc can influence on the component behavior, let say you have a css override in the doc that break/fix the component.

@oliviertassinari oliviertassinari changed the title Fix issue #254, focus cell fully visible [DataGrid] Fix focus cell visibility Sep 9, 2020
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! labels Sep 9, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 9, 2020

@dtassone I have updated the pull request metadata to follow the standard, what do you think about it? The changes:

@oliviertassinari
Copy link
Member

Fix #254

The behavior seems correctly fixed.

Should we add a test cases to avoid regressions in the future?

I have found #258. I think that we need a test to avoid regressions, this seems to be a hard problem :)

@dtassone
Copy link
Member Author

Fix #254

The behavior seems correctly fixed.

Should we add a test cases to avoid regressions in the future?

I have found #258. I think that we need a test to avoid regressions, this seems to be a hard problem :)

#258 is another issue and he's still there

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 10, 2020

#258 is another issue and he's still there

Yeah, agree, I have only open the issue to keep track of it, I doubt it's important for us NOW (maybe later). And it's definitely different to this one. My objective was to make the point that regression tests are likely valuable for this problem.

@dtassone dtassone merged commit cde8cee into mui:master Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Focused cell should always be fully visible
2 participants