-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS, Mac] Fix for Picker title is not displayed again when SelectedIndex is set to -1 #30486
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
base: main
Are you sure you want to change the base?
[iOS, Mac] Fix for Picker title is not displayed again when SelectedIndex is set to -1 #30486
Conversation
Hey there @@HarishwaranVijayakumar! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that when a Picker’s SelectedIndex is reset to –1 on iOS/macOS, the original title (placeholder) is displayed again.
- Clear the native control’s
Text
before updating the placeholder inUpdatePicker
- Add a new UI test in
TestCases.Shared.Tests
to verify the placeholder reappears - Provide a HostApp page for the UI test under
TestCases.HostApp
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Core/src/Platform/iOS/PickerExtensions.cs | Clear platformPicker.Text before calling UpdatePickerTitle to allow the placeholder to show |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue30463.cs | Add a UITest to toggle SelectedIndex and verify the title returns |
src/Controls/tests/TestCases.HostApp/Issues/Issue30463.cs | Introduce a ContentPage with a Picker and Button for UI testing |
App.WaitForElement("ToggleSelectedIndexBtn"); | ||
App.Tap("ToggleSelectedIndexBtn"); | ||
var pickerText = App.WaitForElement("RegainingPickerTitle").GetText(); | ||
#if ANDROID || MACCATALYST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include iOS in the positive branch of this conditional (e.g. #if ANDROID || IOS || MACCATALYST
), since after resetting SelectedIndex
the placeholder/title should also be visible on iOS.
#if ANDROID || MACCATALYST | |
#if ANDROID || IOS || MACCATALYST |
Copilot uses AI. Check for mistakes.
App.WaitForElement("ToggleSelectedIndexBtn"); | ||
App.Tap("ToggleSelectedIndexBtn"); | ||
var pickerText = App.WaitForElement("RegainingPickerTitle").GetText(); | ||
#if ANDROID || MACCATALYST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also include IOS
?
|
||
[Test] | ||
[Category(UITestCategories.Picker)] | ||
public void PickerShouldRegainTitle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is failing on iOS:
Assert.That(pickerText, Is.Empty)
Expected: <empty>
But was: "Select an item"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz,I verified it locally, and it passes on iOS. Therefore, I updated the test case to use visual verification.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issue Details
Root Cause of the issue
On iOS/macOS, a UITextField (which MauiPicker inherits from) only shows the AttributedPlaceholder when the Text property is null or empty
When SelectedIndex changes from a valid index (like 2) to -1, the Text property still retained the previous selected item's text
Since Text wasn't cleared, the placeholder (picker title) couldn't be displayed, even though UpdatePickerTitle() was being called
Description of Change
Issues Fixed
Fixes #30463
Tested the behaviour in the follwing platforms
Output
Beforefix.mov
Afterfix.mov