-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[data grid] Skip tab focus on custom cell #11999
Comments
Hi @Edelf Your use case is indeed interesting.
I am not sure if this is possible at all. Let me check that. |
Hi @michelengelen , thank you for the reply. Setting the col to In the example above, whenever we change the |
Ah, yes. I forgot about that. My bad 🙇🏼 The reason for the keydown handler is that with this we can determine where the focus comes from and if we need to skip the next field or not. Stay tuned ... I will have an answer today! |
Ok, I managed to build an example for your use case: Skip column on keyboard navigation It makes use of the before mentioned methods and ideas (to some extent). Have a look an tell me if this is something you can use! |
I adapted your proposed solution to my usecase and it's not working properly with It would also increase considerably the complexity of the solution taking into consideration some dynamic columns and custom cells. Thank you again for the reply and time spent on this. |
Ah, I was not aware that you were referring to the row being in edit mode. |
@Edelf Your use-case is indeed an interesting one. I think you can use the initial recommendation by @michelengelen of making the column Now, the problem the value is not correctly being computed in the row passed to the
But if you read the explanation of the
You can use this for your benefit to set the correct value for the <DataGrid
processRowUpdate={(recievedRow: GridValidRowModel) => {
console.log("recievedRow", recievedRow); // includes incorrect value for `total`
const updatedRow = {
...recievedRow,
total: computeTotal(recievedRow).valueOf(), // update the value
};
return updatedRow; // update the value in Grid's state
}}
/> Now it solves the problem of value not synchronizing with the Grid state, but another problem is still there which was previously being solved by the You can solve this by passing a custom cell to the I tried to do that in this csb example. Let me know if it solves your use cases. Thank You. |
Thank you @MBilalShafi / @michelengelen for the time you spent on this. I tried to simplify our use cases on my initial post, and for that case your proposed solution would work! For instance (built on top of your solution): https://stackblitz.com/edit/react-wsb1ap-6eu6rq?file=Demo.tsx |
@zannager any specific reason for that status change? |
@Edelf Does |
@MBilalShafi here is the example, using |
Thanks for adding the advanced use case. It's because, until the edit change is not committed, we keep passing the previous row values to the IMO, we can pass the non-committed updated row values to the Here is a demo based on that PR built on top of the last demo you shared: https://codesandbox.io/p/sandbox/to-delete-forked-jn874w?file=%2Fsrc%2FApp.tsx%3A218%2C29 Let me know if it'll solve your issue. |
@MBilalShafi thank you again for your time. Your example works, except for:
|
I can not reproduce it, for me both TAB and SHIFT + TAB work as expected. Could you check again and possibly share the reproduce steps if that may help?
That's because the cell is by default memoized for performance reasons and is not re-rendered until there is a state update (or Here's an updated example: https://codesandbox.io/p/sandbox/to-delete-forked-8zqrsm?file=%2Fsrc%2FApp.tsx%3A215%2C26 Update: There's a dependency fetch error with the codesandbox ci packages due to which the sandbox is not rendering properly, I'll look into it in a while, meanwhile you can test the change locally if you want. |
Hey @Edelf, first of all, apologies for getting back to you so late, I was caught up with many things. After analyzing the problem again, I think the root of the problem is the row edit not being committed when a cell is switched using Tab or Shift + Tab due to which we had to introduce many hacks in the examples above, still not able to solve all the problems. The row editing is by definition designed not to update the values in the state before the row change is committed. An alternate way could be to use cell editing, using which we could build a similar solution (it could even be better since the Tab navigation works on multiple rows) Here's the example I built on top of the single-click editing demo which might give a similar experience with the interactions smoother and the Tab navigation fixed: https://stackblitz.com/edit/react-u9chwq-nvpr8h?file=Demo.tsx,package.json,GridCell.tsx,node_modules%2F%40mui%2Fx-data-grid%2Fmodels%2FcolDef%2FgridColDef.d.ts A small test on the above demo: tab.mp4I'd appreciate you checking it out and letting me know if this is a direction you can go forward with! Thank you! |
The issue has been inactive for 7 days and has been automatically closed. |
The problem in depth
For context, the following scenario is a consequence of the solution proposed on the following issue: #9489
When using the keyboard tab to navigate between cells, I need to skip a specific cell that displays the result of a calculation. This cell cannot be flagged as
editable: false
since it needs to display the result in real-time whenever the other cells are changed.https://codesandbox.io/p/devbox/5jyv2k?file=%2Fsrc%2FDemo.tsx
On the example above, cell
Total
is the result ofQuantity * Price
. ✅Whenever
Quantity
orPrice
changes,Total
needs to update. ✅Using the keyboard to navigate from cell to cell, I need to be able to reach the last cell
Other
, skipping/without focusingTotal
similar to if the cell waseditable: false
❌How can I achieve this?
Your environment
`npx @mui/envinfo`
Search keywords: tab, focus, keyboard navigation
Order ID: 68154
The text was updated successfully, but these errors were encountered: