For large screens, because it can be problem for mobile devices. It would be good if we can make this automatic out of the box.
@hikalkan I have several ideas and I would like your opinion.
<Autofocus> that would wrap an input. In the backend, it would detect screen size or device type and then focus the wrapped input. It would do this only the first time page is loadedExample
<Autofocus>
<TextEdit />
</Autofocus>
Form or Validations components with Autofocus parameter. This parameter would say what input needs to be focused on the first load.Example
<Form Autofocus="@search">
<TextEdit @ref="search" />
</Form>
PS. we already have a Focus() method on TextEdit that we can use to set focus programmatically. So we can use that as a first solution. But we still need to detect if it's in mobile device.
Modals are a little problematic since they are always loaded on the page so we cannot use page-load to focus the input. SO for modals I propose:
.Show() or Visible="true" I can autofocus the input<Modal Autofocus="@search">
<ModalContent>
<ModalBody>
<TextEdit @ref="search" />
</ModalBody>
</ModalContent>
</Modal>
@cotur and @ilkayilknur I would also like your feedback on this if possible
Modal Autofocus="@search" and <Form Autofocus="@search"> seems fine to me.
Is it possible to write something like that?
<TextEdit AutoFocus="true"/>
I also like the first declarative approach. Honestly, I wouldn't say I like giving names to the components and pass them to the other components. This makes code more complicated.
I suppose <TextEdit AutoFocus="true"/> is not possible. Otherwise, it would be my first choose :)
@ilkayilknur <TextEdit AutoFocus="true"/> is the easiest approach, but it would work for pages only. It would not work well once it's placed inside of a modal.
Modal Autofocus="@search" and <Form Autofocus="@search"> makes more sense as that way we cover most of the things.
馃 Maybe when I do this <TextEdit AutoFocus="true"/> and I detect TextEdit is placed in modal, it would be automatically detected by the Modal and then focused...
馃 Maybe when I do this
and I detect TextEdit is placed in modal, it would be automatically detected by the Modal and then focused...
This looks like the best way.
I agree, and I will try and see how it goes.
I made a quick prototype and <TextEdit Autofocus="true"/> when placed in Modal is working really well. There are some limitations though.
Autofocus.
Most helpful comment
I suppose
<TextEdit AutoFocus="true"/>is not possible. Otherwise, it would be my first choose :)