BUG: On-screen keyboard appears when dragging slider

NOTE: I’m on the develop branch of JUCE, pulled yesterday. Last commit:

commit 31d4f9059d2fe0f51b6dbc11f8530139d82c9b17 (HEAD -> develop)
Author: attila <attila@juce.com>
Date:   Wed Apr 27 15:44:45 2022 +0200

    Android:  Fix dismissing screen keyboard when interacting with TextEditor

I have a slider, which has its associated textbox.
On macOS, as I drag the slider the value in the textbox changes. Correct behaviour!
However on Android, dragging the slider pops up the on-screen keyboard.

Here are all the code-references to the slider:

    Slider sliderPurity;

        sliderPurity.setRange(0, 15, 1);
        sliderPurity.setValue(0, dontSendNotification);
        sliderPurity.setTextBoxStyle(Slider::TextBoxRight, true, 30, 30);

        sliderPurity               .setBounds(r.removeFromTop(50));  r.removeFromTop(10);

    float getFracPure() {
        return sliderPurity.getValue() / sliderPurity.getMaximum();

One thing I notice in the screenshots:

… the caret is already in a PRIOR textbox. So it’s possible that is influencing the behaviour. A few days ago I reported an issue of the keyboard NOT popping up in response to a textbox gaining focus, and it was patched in develop branch.

Could it be that my slider attempts to take focus, is denied (sliderPurity.setTextBoxIsEditable(false); maybe?), focus returns to the PRIOR textbox and (thanks to the latest patch) the keyboard appears?

I’m assuming the slider and editor have the same parent component.

I think what happens is this:

  • Dragging the slider tries to give it keyboard focus.
  • The slider doesn’t want focus, so the parent is given a chance to take focus.
  • The parent itself also doesn’t want focus, so it checks each of its children to see whether they want focus.
  • The TextEditor does want focus, so focus is passed to that component.

One potential workaround would be to make the TextEditor’s parent component keyboard-focusable. That way, when the click event is propagated up the component hierarchy from the slider, the editor’s parent will take focus, rather than passing it on to the editor.

As an alternative, I’ve pushed a change to TextEditor that will avoid showing the onscreen keyboard unless the editor is clicked directly:

Please try this out and let me know if you encounter any issues that mean that this isn’t an acceptable fix.