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

Remove zero width space special case from public API #3136

Open
mhsmith opened this issue Jan 27, 2025 · 3 comments
Open

Remove zero width space special case from public API #3136

mhsmith opened this issue Jan 27, 2025 · 3 comments
Labels
enhancement New features, or improvements to existing features.

Comments

@mhsmith
Copy link
Member

mhsmith commented Jan 27, 2025

Label, Switch and Button all document their text property as follows:

None, and the Unicode codepoint U+200B (ZERO WIDTH SPACE), will be interpreted and returned as an empty string. Any other object will be converted to a string using str().

The zero width space special case was added for the benefit of WinForms, where some of these widgets will collapse their height if you give them an actual empty string.

However, there's no need for this implementation detail to complicate the public API. We should follow the same principle as we have on other widgets such as Slider, where if a backend is unable to round-trip a value, then it sets the native value to the best possible approximation, and caches the “true” value so it can be returned to the interface layer unchanged.

@mhsmith mhsmith added the enhancement New features, or improvements to existing features. label Jan 27, 2025
@freakboy3742
Copy link
Member

I agree the U+200B case is an annoying implementation wart; however I'm not necessarily convinced it's worth the effort to resolve. It needs to be documented as an edge case; but it's such an extreme edge case that in practice, it won't actually be impacting on very many users.

The solution is effectively "keep a second authoritative source of state for the widget" - which I'm not wild about as a solution. Yes, it would work, but it's a complication that results in the potential for the widget a the value of the widget to get out of sync.

That said - moving to ValueSource might provide a way to address this - this is effectively moves the source of truth canonically to the ValueSource, with the widget being asked to reflect that source of truth.

@mhsmith
Copy link
Member Author

mhsmith commented Jan 29, 2025

It needs to be documented as an edge case; but it's such an extreme edge case that in practice, it won't actually be impacting on very many users.

The thing is, if I saw documentation like this, my first response would be "what the hell is that", and my second response would be "ah, it's an implementation detail that they've failed to encapsulate properly". That wouldn't make me confident in the quality of the library.

The solution is effectively "keep a second authoritative source of state for the widget"

It can be much more limited than that – just a boolean flag which distinguishes between the values "" and "\u200b". When the value is neither of those, the flag would be ignored and the native widget value would be used directly.

@freakboy3742
Copy link
Member

The thing is, if I saw documentation like this, my first response would be "what the hell is that", and my second response would be "ah, it's an implementation detail that they've failed to encapsulate properly". That wouldn't make me confident in the quality of the library.

That's fair.

The solution is effectively "keep a second authoritative source of state for the widget"

It can be much more limited than that – just a boolean flag which distinguishes between the values "" and "\u200b". When the value is neither of those, the flag would be ignored and the native widget value would be used directly.

That doesn't sound too bad - if a fix for this doesn't fall out of the ValueSource changes, that sounds like a low-effort fix that would be worthwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

2 participants