Search Issue Tracker

By Design

Votes

0

Found in

2019.1.0a12

2019.1.0b2

2019.2.0a1

Issue ID

1126687

Regression

Yes

Text in a TextField does not get selected when calling TextField.Focus and TextField.SelectAll

UI Toolkit

-

How to reproduce:
1. Open attached project ("TextFieldBug.zip")
2. Go to Window > TextField BUG to open TestEditorWindow
3. Press button number 1

Expected result: Text appears and gets selected
Actual result: Text appears but does not get selected

Reproducible with: 2019.1.0a12, 2019.1.0b2, 2019.2.0a5
Not reproducible with:
2019.1.0a7 and earlier (errors because of the missing elements),
2019.1.0a8, 2019.1.0a9 (worked fine)

Notes:
2019.1.0a10-2019.1.0a11 SelectAll works, but only the second time you use it, after making the text visible.

Workaround:
You need to use these 3 lines in addition to Focus and SelectAll:
var textInput = m_TextField.Q("unity-text-input");
m_TextField.delegatesFocus = true;
textInput.visible = true;

  1. Resolution Note:

    We only need this line:

    m_TextField.Q("unity-text-input").visible = true;

    before trying to focus the field.

    The reason why m_TextField.visible = true is not sufficient is that as of today, visibility is a hierarchical concept. We need a styling pass for the visible attribute to propagate to the children.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.