# Perspective Focus

**URL:** <https://forum.inductiveautomation.com/t/perspective-focus/53750>\
**Category:** Ignition\
**Created:** [December 3, 2021, 7:42pm UTC](https://forum.inductiveautomation.com/t/perspective-focus/53750 "2021-12-03T19:42:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [December 3, 2021, 7:42pm UTC](https://forum.inductiveautomation.com/t/perspective-focus/53750/1 "2021-12-03T19:42:44Z")

</div>

Hello all,

I am trying to gain focus on a component in perspective. My component is sitting inside a nested flex container.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/d/6dd8afab6979f8e96c1f184737379a5bf5ed5e38.png)

I tried to supply this code into the startup event of the component itself:

`self.focus()`

did not work, then tried to write the focus command on the root container and the view itself did not work either. Usually this should work but I do not know what I am doing wrong here.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [December 3, 2021, 8:39pm UTC](https://forum.inductiveautomation.com/t/perspective-focus/53750/2 "2021-12-03T20:39:20Z")

</div>

I don’t know how well applying focus works if a component is moving around. You MIGHT be running into a situation where the component starts up (and therefore fires off its onStartup Event), but the component is then moved around as the flex container grows/shrinks/flexes due to other components. Just out of curiosity, does it work if you wait for 3 seconds before invoking `self.focus()`?

```auto
from time import sleep
sleep(3)
self.focus()

```

---

<div class="post-metadata">

**Author:** ![pkhoshroo](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pkhoshroo/32/26801_2.png) [@pkhoshroo](https://forum.inductiveautomation.com/u/pkhoshroo)\
**Post date:** [December 7, 2021, 2:46pm UTC](https://forum.inductiveautomation.com/t/perspective-focus/53750/3 "2021-12-07T14:46:57Z")

</div>

That fixed the issue. Thank you!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 12, 2025, 4:00pm UTC](https://forum.inductiveautomation.com/t/perspective-focus/53750/5 "2025-03-12T16:00:19Z")

</div>

That's a different topic. Please don't hijack this one. Start a new thread.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [March 12, 2025, 4:18pm UTC](https://forum.inductiveautomation.com/t/perspective-focus/53750/6 "2025-03-12T16:18:47Z")

</div>

The fact that using `sleep` is being identified as the solution makes me feel the need to ask for more votes on my suggestion of an `onLoad` alternative to `onStartup`:

> **[Perspective view onLoad event that fires when the view is done loading |...](https://inductiveautomation.canny.io/ignition-features-and-ideas/p/perspective-view-onload-event-that-fires-when-the-view-is-done-loading)**
>
> This would be the only clean way of ensuring that, for example, an input .focus() would execute at the right time... https://forum.inductiveautomation.

A robust platform would never require using a hack like `sleep`. I continue to use `Timer` for things like this, but that's not much better than `sleep`.
