Search Unity

TextField Focus with Cursor Selection

Discussion in 'UI Toolkit' started by opsive, Jan 20, 2020.

  1. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    When a new window opens I'd like for the textfield to have focus with the cursor selected so the user can type immediately without first having to click within the textfield:

    upload_2020-1-20_11-5-23.png

    I can call TextField.Focus but this only highlights the textfield in blue, it doesn't bring the cursor selection with it so the user still has to click within the textfield. Is there a way to do this with the current API?

    Thank you!
     
    Xarbrough likes this.
  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    1,003
    This is a known issue. To work around this, you'll have to focus the sub-element:

    Code (CSharp):
    1. textField.Q("unity-text-input").Focus();
     
    opsive likes this.
  3. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Thank you - that worked perfectly.