From 5c8575dd5208e43a68fd9bdb88793bb9451556bb Mon Sep 17 00:00:00 2001 From: Carlos Lima Date: Tue, 24 Sep 2024 09:07:56 -0300 Subject: [PATCH] [PBNTR-490] Fixing minimizing the dropdown when clicking outside (#3688) **What does this PR do?** Fixing dropdown doesn't minimize when clicking outside of the field. **How to test?** Steps to confirm the desired behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See addition/change #### Checklist: - [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [x] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code. --- .../_multi_level_select.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/playbook/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx b/playbook/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx index 57a68acab6..911d22ab02 100644 --- a/playbook/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +++ b/playbook/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx @@ -88,6 +88,9 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => { item: [] }) + const arrowDownElementId = `arrow_down_${id}` + const arrowUpElementId = `arrow_up_${id}` + const modifyRecursive = (tree: { [key: string]: any }[], check: boolean) => { if (!Array.isArray(tree)) { return @@ -173,7 +176,12 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => { useEffect(() => { // Function to handle clicks outside the dropdown const handleClickOutside = (event: any) => { - if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { + if ( + dropdownRef.current && + !dropdownRef.current.contains(event.target) && + event.target.id !== arrowDownElementId && + event.target.id !== arrowUpElementId + ) { setIsDropdownClosed(true) } } @@ -260,7 +268,6 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => { // Handle click on input wrapper(entire div with pills, typeahead, etc) so it doesn't close when input or form pill is clicked const handleInputWrapperClick = (e: any) => { - e.stopPropagation() if ( e.target.id === "multiselect_input" || e.target.classList.contains("pb_form_pill_tag") @@ -518,16 +525,20 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => { {isDropdownClosed ? ( -
+
) : ( -
+