Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question TextField USS get when typing

Discussion in 'UI Toolkit' started by AidanHorton, Jan 7, 2023.

  1. AidanHorton

    AidanHorton

    Joined:
    Apr 25, 2014
    Posts:
    5
    Simple query - I have a TextField, and I want to change the background colour while the user is typing.
    Focus doesn't seem to accomplish what I want - it doesn't seem to change under any state.

    What pseudo-selector do I use to change the background colour while the user is typing?
     
  2. C-UITools

    C-UITools

    Unity Technologies

    Joined:
    Jun 23, 2021
    Posts:
    22
    Could you provide additional information about your issue? Specifically:
    1. When you say that focus does not accomplish what you want, do you mean that the background color is not changed when you are typing, or that it also changes when you are selecting text?
    2. Do you want the color of the entire TextField (Label + TextInput) to change, or just the color of the TextInput?
    3. What selectors are you using to try to achieve this effect?
    Thank you!
     
  3. AidanHorton

    AidanHorton

    Joined:
    Apr 25, 2014
    Posts:
    5
    Hi!

    If I use :focus in the CSS, that doesn't apply when you're tying anything. My thinking is that it's the child text that's technically focused - but as far as I can tell, it's not possible to CSS in an upwards direction, IE, when the text is focused, then do X to the parent in CSS.
    I just want the text input box that the text resides in to be able to have custom styles while typing is occurring, or the text inside is selected/focused.

    I've tried as many selectors as I've seen in the documentation and that I know - and none of them work.