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: Prevent focus reset for DataGridTemplateColumn #4206

Merged
4 commits merged into from
Sep 3, 2021
Merged

fix: Prevent focus reset for DataGridTemplateColumn #4206

4 commits merged into from
Sep 3, 2021

Conversation

lukeblevins
Copy link
Contributor

@lukeblevins lukeblevins commented Aug 31, 2021

Note: This is a copy of the previously reviewed work with a new branch name

Fixes #2493

This prevents DataGrid from assuming focus should be reset back to itself when a control inside DataGridTemplateColumn gains focus. This is my first WCT PR, so please go easy on me 😆

PR Type

What kind of change does this PR introduce?

Bugfix

What is the current behavior?

Trying to open a control like CalendarDatePicker from within a DataGridTemplateColumn doesn't work, as there is specific behavior to detect when DataGrid loses focus and return it. This doesn't make much sense for controls which require focus to function properly.

What is the new behavior?

When the DataGrid loses focus, we now specifically detect if the editing column is a DataGridTemplateColumn and alter the behavior to accommodate this.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

I'm unsure if this is the best way to do this, but it makes the most sense given how DataGrid already has the capability to detect the editing element and column type.
Additional context before branch rename: #4206
Related: unoplatform/uno#6543

@ghost
Copy link

ghost commented Aug 31, 2021

Thanks duke7553 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from michael-hawker, azchohfi and Rosuavio August 31, 2021 15:25
@ghost ghost added bug 🐛 An unexpected issue that highlights incorrect behavior DataGrid 🔠 Issues on DataGrid control labels Aug 31, 2021
@michael-hawker michael-hawker added this to the 7.1 milestone Aug 31, 2021
Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Hmm, I think we want to update the sample here to show this in the example (using the First Ascent column) and expand on how we'd expect a developer to do this behavior?

I was playing a bit around as there's two parts to the DataGridTemplateColumn the CellTemplate and the CellEditingTemplate (as per the original bug vs. the work-around using read-only mode). So, I'd expect you may also want to show the cell as just a text date first before showing the picker vs. always being modifiable? Want to make sure we cover both scenarios with a fix (which I think this does? it's harder to test the existing behavior as the shipped sample app can't use the template column).

I made some updates to the XAML and data model backing the DataGrid sample here to show this (and rebased on top of the latest main as your branch was out of date): https://github.com/michael-hawker/UWPCommunityToolkit/tree/dg-focusreset

Saw in the bug thread I had to use DateTimeOffset for binding vs DateTime which is odd but is important. Seems to work like a charm though with the updated example! 🎉

Wonder though if there's the same UX problems this way we had with the ComboBox as well from #3161/#4220 with how CalendarPicker would behave, right? I also noticed that DataGridTemplateColumn has overrides vs. events, so it's not easy to apply the same fix without asking the developer to create their own subclass of the template column, but then templating is a bit harder to build in that way... would be nice for us to support events, so I'll open a separate issue for that.

Thoughts on all this? @duke7553 if you're happy with my updated demo, please feel free to merge into your branch here for the PR or if you want me to force-push to your remote one (assuming you checked collaborators have write access to the branch in the PR).

@michael-hawker
Copy link
Member

Ah, I found the parent DataGrid event. I updated my sample and fixed it so you only need 2 clicks over 3 for the Calendar cell.

@duke7553 let me know how we can update your branch the best with the new sample update. I opened a PR on your fork so we could discuss that over there. https://github.com/duke7553/WindowsCommunityToolkit/pull/1

@net-foundation-cla
Copy link

net-foundation-cla bot commented Sep 2, 2021

CLA assistant check
All CLA requirements met.

@net-foundation-cla
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ duke7553 sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

8,Manaslu,8163,Manaslu Himalaya,28d33m00sN 84d33m35sE,3092,Cho Oyu,05/9/1956,49 (45)
9,Nanga Parbat,8126,Nanga Parbat Himalaya,35d14m14sN 74d35m21sE,4608,Dhaulagiri,07/03/1953,52 (67)
10,Annapurna I,8091,Annapurna Himalaya,28d35m44sN 83d49m13sE,2984,Cho Oyu,06/03/1950,36 (47)
11,Gasherbrum I,8080,Baltoro Karakoram,35d43m28sN 76d41m47sE,2155,K2,01/01/1958,31 (16)
Copy link
Member

Choose a reason for hiding this comment

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

I grabbed a couple of the months/dates for testing with the Calendar Picker, but wasn't going to enter them all, so opened #4224 for tracking if a hiking enthusiast wants to help us in the future.

Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @duke7553! I've updated your branch which has updated the PR here with my sample changes. Feel free to take them for a spin if you'd like too.

@ghost
Copy link

ghost commented Sep 3, 2021

Hello @michael-hawker!

Because this pull request has the auto merge :zap: label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@lukeblevins
Copy link
Contributor Author

Everything looks great. Thank you!

@ghost ghost merged commit 3f29bde into CommunityToolkit:main Sep 3, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merge ⚡ bug 🐛 An unexpected issue that highlights incorrect behavior DataGrid 🔠 Issues on DataGrid control
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataGrid DataGridTemplateColumn CalendarDatePicker and DatePicker Flash Then Desappear!
3 participants