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

[SmartHint] Hint placement for "readonly" controls #3764

Merged
merged 5 commits into from
Jan 10, 2025
Merged

[SmartHint] Hint placement for "readonly" controls #3764

merged 5 commits into from
Jan 10, 2025

Conversation

nicolaihenriksen
Copy link
Contributor

Fixes #3762

Initially I thought this was just a fix for the ComboBox styles, but it turns out that it was actually a common issue when the control is "readonly" (e.g. TextBox.IsReadOnly=true or ComboBox.IsEditable=False).

While investigating the root cause, I stumpled upon 2 other issues that I fixed as well. So this PR covers:

  1. Fixing a very weird issue in the SmartHint demo app page, where the initial calculation of hint would sit on top of the prefix text. I was not able to reproduce this outside of the SmartHint demo app which puzzles me quite a bit. To "fix" it, I added a hack to the demo app, where it simply overrides the prefix/suffix texts in a Loaded event handler on the demo app page itself; this seems to kick the calculation into gear. Another way to manually "fix" it is to simply clear the prefix text in the UI, and then set it to back to what it was (or anything non-emtpy basically).

  2. The Material Design 2 spec is quite clear in the visualization of a ComboBox in various states. We did not follow that completely since we did not float the hint once the drop-down was visible. A small change in SmartHint.cs regarding HintHost.IsKeyboardFocusWithin fixes that issue. See the MD2 spec here (scroll down a small bit further to the "Behavior" section).

  3. Fixes the actual issue reported in the linked issue above. For "readonly" controls, we have a "business rule" that the prefix/suffix texts are always visible. For editable controls, the prefix/suffix visibility depends on the value of TextFieldAssist.PrefixTextVisibility which defaults to WhenFocusedOrNonEmpty. In the "readonly" case, the fact that the prefix/suffix is always visible was not accounted for, this PR changes that.

Before

image

image

After

image

image

@corvinsz @Keboo Could you guys please check out this branch and give it a short spin? Try to play around with Smart Hint and Fields line up demo pages, the former gives you a lot of control over how the hint/prefix/suffix and control behavior in general. It also showcases the different alignments, as well as all the controls supporting the SmartHint control.

And a small note-to-self: Think twice before undertaking a major refactoring of something as complex as the SmartHint and the placement-hell that lies within...

@nicolaihenriksen nicolaihenriksen added this to the 5.2.1 milestone Jan 9, 2025
@corvinsz
Copy link
Contributor

corvinsz commented Jan 9, 2025

@nicolaihenriksen I have fiddled around with your branch and everything I have tested works fine.
I have no objections, good work!

While testing I have noticed a problem (#3766) with the Pre-/Suffix but that's probably for another PR, not for this one.

@nicolaihenriksen
Copy link
Contributor Author

While testing I have noticed a problem (#3766) with the Pre-/Suffix but that's probably for another PR, not for this one.

Thank you for testing!! I have commented on the new issue; I think it is the default "read only" mode of the ComboBox that makes it give off the wrong impression. Let me know if my comment makes sense...

@corvinsz
Copy link
Contributor

corvinsz commented Jan 9, 2025

Yes, your comment does make sense, my bad. I closed it. 😆

nicolaihenriksen and others added 5 commits January 9, 2025 22:20
According to the "Behavior" section of the "Menus" page in the link below, the hint should float even when there is no selection, but the popup is open.

https://m2.material.io/components/menus#exposed-dropdown-menu
The issue was present for all controls once they are in "readonly" state. Special handling of the case where the element is readonly, and the hint should follow the prefix/suffix needed to be added because of the "business rule" that prefix/suffix is always visible when the element is "readonly".
@Keboo Keboo enabled auto-merge (squash) January 10, 2025 06:32
@Keboo Keboo merged commit 070e8bb into master Jan 10, 2025
2 checks passed
@Keboo Keboo deleted the fix3762 branch January 10, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Faulty Hint in ComboBox Styles
3 participants