Skip to content

[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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

HarishwaranVijayakumar
Copy link
Contributor

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

  • When an item is selected in the Picker, setting SelectedIndex back to -1 does not restore the original title.

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

  • Clear the text property before setting the placeholder

Issues Fixed

Fixes #30463

Tested the behaviour in the follwing platforms

  • - Windows
  • - Android
  • - Mac
  • - iOS

Output

Before Fix After Fix
Beforefix.mov
Afterfix.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jul 8, 2025
Copy link
Contributor

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.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jul 8, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@HarishwaranVijayakumar HarishwaranVijayakumar marked this pull request as ready for review July 10, 2025 04:49
@Copilot Copilot AI review requested due to automatic review settings July 10, 2025 04:49
@HarishwaranVijayakumar HarishwaranVijayakumar requested a review from a team as a code owner July 10, 2025 04:49
Copy link
Contributor

@Copilot Copilot AI left a 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 in UpdatePicker
  • 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
Copy link
Preview

Copilot AI Jul 10, 2025

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.

Suggested change
#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
Copy link
Contributor

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()
Copy link
Contributor

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"

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-picker Picker community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios platform/macos macOS / Mac Catalyst
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS, Mac] Picker title is not displayed again when SelectedIndex is set to -1
2 participants