/    Sign up×
Bounties /Pin to ProfileBookmark

how to achieve functionality that when `Esc` button is pressed then close the `CheckPicker` dropdown in react and rsuite

to post a answer
React

4 Replies

Davinci•003 auto-replyYou can achieve this functionality by using the keyup event listener in JavaScript. The keyup event listener will listen for when a key is pressed and then you can check if the key pressed is the Esc key. If it is, you can then call a function to close the CheckPicker.

Here is an example of how you can achieve this:


document.addEventListener('keyup', (event) => {
if (event.key === 'Escape') {
// Close the CheckPicker
}
});

Was this helpful?

Copy linkTweet thisAlerts:
@DuaneDamianJul 10.2023 — It seems like you're experiencing a cross-origin request issue and facing difficulties with session cookies on your website. Here are a few suggestions to help you troubleshoot the problem:

Cross-Origin Resource Sharing (CORS): The error message you mentioned indicates that the server is not properly configured to handle CORS requests. To enable CORS, you need to make sure the server responds with the appropriate headers. You can modify your PHP files to include the following header:

header("Access-Control-Allow-Origin: *");

This allows requests from any origin. However, you can replace * with the specific origin URL from where your requests are being made for better security.

Handling OPTIONS requests: The "OPTIONS" request you mentioned is a preflight request that browsers send as part of CORS. To handle it properly, you can add the following code at the beginning of your PHP files:

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
exit;
}

This code allows the required HTTP methods (POST, OPTIONS) and headers (Content-Type, Authorization, X-Requested-With) for your requests.

Credentials and SameSite attribute: Since you're working with session cookies, you need to ensure that the cookies are being sent with each request. Modify the cookie parameters during session creation to include the secure, httponly, and samesite attributes:

session_set_cookie_params([
'lifetime' => $maxlifetime,
'path' => '/',
'domain' => $_SERVER['HTTP_HOST'],
'secure' => true,
'httponly' => true,
'samesite' => 'None'
]);


Setting 'samesite' => 'None' ensures that the cookies can be sent with cross-site requests. However, note that this attribute requires the secure flag to be set, meaning the site must be served over HTTPS.

Verify HTTPS configuration: Ensure that your website is properly configured to use HTTPS. Browsers enforce stricter rules for cross-origin requests, especially when it comes to sending cookies. Make sure your website is being served over HTTPS to avoid any security issues.

Testing with different browsers: Test your website with different browsers to see if the issue persists across all of them. Different browsers may handle cross-origin requests and cookies differently, so this can help identify if the problem is browser-specific.

Inspect network requests: Use the browser's developer tools (e.g., Chrome DevTools, Firefox Developer Tools) to inspect the network requests and responses. Check the request headers and response headers to see if the required CORS headers and session cookies are being set correctly.

By implementing these suggestions, you should be able to resolve the issue with session cookies and cross-origin requests on your website. Remember to clear any existing cookies in your browser before testing the changes.
Copy linkTweet thisAlerts:
@prJul 13.2023 — It looks like rsuite's CheckPicker already handles the esc key if the picker is focused.
Copy linkTweet thisAlerts:
@nirajchaurasiyaAug 18.2023 — Checkpicker will be closed automatically when the ESC button is pressed.
If not, you can achieve this functionality with a few lines of code in ReactJS.
For instance,
// key press or keyup or keydown
document.addEventListener('keyup', (event) => {
if (event.key === 'Escape' || event.key === 'escape') {
// Close the CheckPicker
}
});
×

Success!

Help @chenathy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...