Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard Doesn't Open for CupertinoSearchTextField in CupertinoActionSheet or CupertinoAlertDialog #54

Open
Micoder-dev opened this issue Jun 29, 2024 · 2 comments

Comments

@Micoder-dev
Copy link

Description
When using CupertinoSearchTextField or any text field inside CupertinoActionSheet or CupertinoAlertDialog, the keyboard does not open as expected.

Code Sample
Below is a code snippet demonstrating the issue:

val focusRequester = remember { FocusRequester() }

CupertinoActionSheet(
    visible = showChangePasswordSheet,
    onDismissRequest = {
        showChangePasswordSheet = false
    },
    title = {
        CupertinoText("Change Password")
    },
    message = {
        CupertinoText("Enter your old password and new password to change your password.")
    },
    properties = DialogProperties(
        dismissOnBackPress = true,
        dismissOnClickOutside = true
    )
) {

    default(onClick = {}) {
        CupertinoSearchTextField(
            modifier = Modifier.focusRequester(focusRequester).focusable(true),
            value = oldPassword,
            onValueChange = {
                oldPassword = it
            },
            paddingValues = CupertinoSearchTextFieldDefaults.PaddingValues,
            cancelButton = {},
            placeholder = {
                CupertinoText("Old Password")
            },
            leadingIcon = {},
        )

        LaunchedEffect(Unit) {
            delay(500)
            focusRequester.requestFocus()
        }

    }

    default(onClick = {}) {
        CupertinoSearchTextField(
            value = oldPassword,
            onValueChange = {
                oldPassword = it
            },
            paddingValues = CupertinoSearchTextFieldDefaults.PaddingValues,
            cancelButton = {},
            placeholder = {
                CupertinoText("New Password")
            },
            leadingIcon = {},
        )
    }

    default(onClick = {}) {
        CupertinoSearchTextField(
            value = oldPassword,
            onValueChange = {
                oldPassword = it
            },
            paddingValues = CupertinoSearchTextFieldDefaults.PaddingValues,
            cancelButton = {},
            placeholder = {
                CupertinoText("Confirm Password")
            },
            leadingIcon = {},
        )
    }

    default(
        onClick = {}
    ) {
        CupertinoText("Confirm")
    }
    cancel(
        onClick = {
            showChangePasswordSheet = false
        }
    ) {
        CupertinoText("Cancel")
    }
}

Steps to Reproduce

  • Implement the code above in your Compose project.
  • Trigger the display of the CupertinoActionSheet.
  • Try to focus on any CupertinoSearchTextField.

Expected Behavior
The keyboard should open automatically when focusing on the CupertinoSearchTextField.

Actual Behavior
The keyboard does not open when focusing on the CupertinoSearchTextField.

Additional Information
Using LaunchedEffect with a delay and focusRequester.requestFocus() does not resolve the issue.

Any help or workaround for this issue would be greatly appreciated.

@alexzhirkevich
Copy link
Owner

Action sheet is not designed to be used with interactive content inside actions. Use modal sheets instead. Or try to set enabled to false for sheet actions

@Micoder-dev
Copy link
Author

  • CupertinoActionSheet

I tried setting enabled to false for the sheet actions, but it doesn't resolve the issue. While modal bottom sheets work fine, using text fields inside CupertinoActionSheet looks really cool and enhances the user experience for certain use cases.

Would it be possible to consider creating a new widget specifically designed to handle interactive content like text fields within CupertinoActionSheet? This feature would be highly beneficial and may be required for various occasions.

Thank you for your consideration!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants