chips-input-layout icon indicating copy to clipboard operation
chips-input-layout copied to clipboard

Chip input always receives focus first

Open majid701 opened this issue 7 years ago • 9 comments

I have noticed that the chips input always receives the focus first in an activity. Is this the desired behaviour? I want to be able to disable this functionality so I can handle the focus order in my activity differently. We could remove the focus from the chips element programmatically afterwards but then the user would notice the cursor switching from one element to another and this is bad user experience.

Has anyone noticed this? Any solution?

thanks

majid701 avatar Feb 23 '18 13:02 majid701

Yea would really love to know if disabling autofocus is possible. I've tried most possible solutions from SO (that worked with EditTexts) but no game :/

najmsheikh avatar Feb 24 '18 07:02 najmsheikh

Thanks for posting this issue!

This problem seems to be happening in the ChipsAdapter whenever the edit text is readjusted to fit the width of the screen in the onGlobalLayout() callback because it calls the requestFocus() on the edit text itself.

I could put a check in there like, 'if auto focus disabled then don't request focus', but that might effect the functionality of the auto sizing though. I'll attempt it then thoroughly test it, but you'd just need to set that in the view's XML layout like app:autoFocusDisabled="false" so that it knows you don't want it to request focus every time it's resized to fit the screen.

tylersuehr7 avatar Apr 05 '18 21:04 tylersuehr7

Any updates about this. because it's very weird and doesn't let users fill other inputs . Any temporary fix will be helpful ..

Regards.

bliveinhack avatar May 08 '18 08:05 bliveinhack

@bliveinhack this is my workaround for now. Try it and let me know if you find a better one. Basically what I'm doing is execute some code with a small delay (50 milliseconds) after the activity has started which clears the focus from the tagview and requests focus on the view you want to receive focus first instead.

(KOTLIN)

override fun onStart() {
    super.onStart()
    // Work around to correct focus issue on tag field
    Timer().schedule(50){
        runOnUiThread {
            // itemTags is ur tagview
            itemTags.clearFocus()
            // the view in your activity/fragment you want to give focus first
            itemTitle.requestFocus() 
            // this is optional but helpful to show keyboard (doesn't work always and on all devices)
            showKeyboardOnView(itemTitle)
        }
    }
}


private fun showKeyboardOnView(view: View) {
    val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.showSoftInput(view,
            InputMethodManager.SHOW_IMPLICIT)
}

majid701 avatar May 08 '18 08:05 majid701

Thanks for workaround.

I'm ended up forking repository and make ChipEditText public so that i can clear focus on scrolling. here is Jitpack https://jitpack.io/#bliveinhack/chips-input-layout/2.4.1 and Repo https://github.com/bliveinhack/chips-input-layout

Regards.

bliveinhack avatar May 09 '18 06:05 bliveinhack

Did you try to set

android:focusable="false"
or
android:focusableInTouchMode="false"

It works fine for me.

DonMat avatar Jun 15 '18 08:06 DonMat

It is not working for me

Nivas78 avatar Jan 17 '19 14:01 Nivas78

Any solution? I'm facing the same issue

XandiVieira avatar Aug 18 '19 21:08 XandiVieira

in chipAdapter.java add // Request focus if (mDataSource.getSelectedChips().size() > 0) { mEditText.requestFocus(); mEditText.setFocusableInTouchMode(true); }

this code. if chips are not empty then only focus otherwise don't focus.

kumarJadhav1993 avatar May 11 '20 12:05 kumarJadhav1993