Automatically select content of TextInput after it got fous

I use iced::widget::focus_next and iced::widget::focus_previous to use the Tab key to move the focus between the widgets of my app.

When a TextInput gains focus the cursor becomes visible and I can edit the content. But it would be very helpful, if the content of the TextInput would be automatically selected after it gains focus.

Is there a way to achieve this?

There is a select_all widget operation for TextInput, you would need to fire that every time your input is focused. Iced doesn’t provide a handler for focus events, but you can implement your own or fire select_all every time you execute focus_next or focus_previous.

Thank you.

Since I use number_input from [iced_aw][iced_aw - Rust] I chose to fire select_all on focus_next and focus_previous events. I had to create my own number_input, though, to give the underlying text_input an id. It would have been easier if the number_input would have forwarded the id()method.

With all operations available that make use of the widget’s id, yes, it’s weird that they haven’t exposed that in number_input. You should create a ticket or even send them a PR :slight_smile: