I am trying to add `clickable` modifier in the `Ba...
# compose-android
a
I am trying to add
clickable
modifier in the
BasicTestField
(with decoration used). but it is not working but if I add
Modifier.clickable
in the decoration then it is working. Any idea why
clickable
is not working when added to top BTF
Code is like below
Copy code
BasicTextField(
    modifier = Modifier
        .fillMaxWidth()
        .height(50.dp)
        .clickable {
            Toast.makeText(this@MainActivity, "Basic text field modifier clickable clicked", Toast.LENGTH_LONG).show()
            Log.d("Tag123", "Basic text field modifier clickable clicked")
        },
    value = value.value,
    onValueChange = {
        value.value = it
    },
    enabled = true,
    decorationBox = { innerTextField ->
        val density = LocalDensity.current
        Row(
            modifier = Modifier
                .clickable {
                    Toast.makeText(this@MainActivity, "Decoration Box of basic text field row modifier clickable clicked", Toast.LENGTH_LONG).show()
                    Log.d("Tag123", "Decoration Box of basic text field row modifier clickable clicked")
                }
                .padding(horizontal = 16.dp, vertical = 8.dp)
                .width(100.dp)
                .height(20.dp)
        ) {
            Box(
                modifier = Modifier
                    .align(Alignment.CenterVertically)
            ) {
                innerTextField()
                if (value.value.text.isEmpty()) {
                    Text(text = "Test")
                }
            }
        }
    }
)
Here first clickable is not working while clickable inside
decorationBox
is working
a
I guess the BasicTextField by default intercepts the click actions to handle the focus events. And that is the reason why the clickable you defined is not getting called. Wherein if you have a clickable inside the decoration box (i.e, your own view), then it will work.
a
Thanks @Ajay Chandran. Is this expected?
a
@Atul Gupta Yes it is.
z
If you need to handle touch events on the whole field you can go one level deeper into the pointerInput modifier and watch events in the initial pass, before clickable sees them.
👍 2
251 Views