ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
50.92k stars 13.51k forks source link

feat: Show popover on text input without click event #29874

Open kevinswartz opened 1 week ago

kevinswartz commented 1 week ago

Prerequisites

Describe the Feature Request

Hi guys, I'm attempting to show a popover on a text input within a form. I would like to show this popover programmatically based on the results of a network request, without passing a trigger event to the popover. The docs I see describe 3 methods of showing popovers: inline popovers, showing via isOpen property, and Controller popovers. All of these methods appear to require a reference to a user-generated event.

Describe the Use Case

Specifically, I have a form with a series of inputs, and a submit button. Upon submitting the form, I make a network request, and based on the results of this request I would like to show a popover on a text input to suggest changes for the user.

Another use case is to use a popover to call attention to a specific button or control when the page loads. For example, after the user loads a page, I could show a popover that says "You can click this button to take some action" to help people get started with the app.

Describe Preferred Solution

One way to accomplish this would be to pass an element reference or ID to to the popover indicating the element I would like to target. I have an old AngularJS/Ionic v1 app that does it this way, and it accomplishes both of the use cases I mentioned.

Describe Alternatives

I'm open to anything that allows me to show a popover asynchronously.

Related Code

No response

Additional Information

I am specifically using React here, but I imagine this would be of benefit to Angular and Vue as well.

kevinswartz commented 3 days ago

I should have thought to try this initially, but I did find a method of showing popovers on elements as per my first use case. If I save the most recent input change event, I can pass this into useIonPopover's present method and I get a working popover.

It's worth noting that this does not solve the second use case, and it feels more like a workaround than a solution, but it does seem to work.