# Custom KeyboardFocusTraverser shadowed by LabelKeyboardFocusTraverser

**URL:** <https://forum.juce.com/t/custom-keyboardfocustraverser-shadowed-by-labelkeyboardfocustraverser/33854>\
**Category:** General JUCE discussion\
**Created:** [June 12, 2019, 9:32am UTC](https://forum.juce.com/t/custom-keyboardfocustraverser-shadowed-by-labelkeyboardfocustraverser/33854 "2019-06-12T09:32:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sparklingRhubarb](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@sparklingRhubarb](https://forum.juce.com/u/sparklingRhubarb)\
**Post date:** [June 12, 2019, 9:32am UTC](https://forum.juce.com/t/custom-keyboardfocustraverser-shadowed-by-labelkeyboardfocustraverser/33854/1 "2019-06-12T09:32:45Z")

</div>

I have a top level component, called `MyFocusContainer`. It has the focus container flag set to true and it overwrites `createFocusTraverser()` to return an instance of a custom `MyCustomKeyboardFocusTraverser : public KeyboardFocusTraverser`.

In this top level component, I have a bunch of subcomponents with controls (e.g. Labels) in them, like this:

```auto
- MyFocusContainer
    - SubComponentA 
        - Label
        - Knob
    - SubComponentB
        - Label
        - Label

```

When I edit a label and press tab, I would expect the focus to traverse the components according to the rules of my `MyCustomKeyboardFocusTraverser`. But that doesn’t happen. I found that `MyCustomKeyboardFocusTraverser` isn’t even instantiated, instead, whenever the focus is in a `Label`, it would not iterate upwards to the FocusContainer and create the focus traverser from there. Instead, it creates a `LabelKeyboardFocusTraverser` right away, which basically just calls the default implementations.

**Because of this I can not apply any custom `KeyboardFocusTraverser`.** At least not without also using a custom Label that stops `LabelKeyboardFocusTraverser` objects from being used instead of my own implementation. **Is that supposed to behave like that?**

---

<div class="post-metadata">

**Author:** ![sparklingRhubarb](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@sparklingRhubarb](https://forum.juce.com/u/sparklingRhubarb)\
**Post date:** [June 19, 2019, 9:39am UTC](https://forum.juce.com/t/custom-keyboardfocustraverser-shadowed-by-labelkeyboardfocustraverser/33854/2 "2019-06-19T09:39:59Z")

</div>

Am I using the wrong approach? How can I implement a custom focusing order?

---

<div class="post-metadata">

**Author:** ![kamedin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kamedin/32/11711_2.png) [@kamedin](https://forum.juce.com/u/kamedin)\
**Post date:** [April 15, 2021, 11:40pm UTC](https://forum.juce.com/t/custom-keyboardfocustraverser-shadowed-by-labelkeyboardfocustraverser/33854/3 "2021-04-15T23:40:44Z")

</div>

I just ran into this -it doesn’t seem a good default behaviour indeed. I think Label should forward focus traversing to the parent, like

```auto
struct ProxyFocusTraverser : KeyboardFocusTraverser
{
    ProxyFocusTraverser (Component* c)
        : c{ c }, traverser{ c->getParentComponent()->createFocusTraverser() } {}

    Component* getNextComponent (Component*) override
    {
        return traverser->getNextComponent (c);
    }

    Component* getPreviousComponent (Component*) override
    {
        return traverser->getPreviousComponent (c);
    }

private:
    Component* c;
    std::unique_ptr<KeyboardFocusTraverser> traverser;
};

KeyboardFocusTraverser* Label::createFocusTraverser()
{
    return new ProxyFocusTraverser (this);
}

```
