Skip to content

Commit

Permalink
[PBNTR-490] Fixing minimizing the dropdown when clicking outside (#3688)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
carloslimasd authored Sep 24, 2024
1 parent fefd66e commit 5c8575d
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -518,16 +525,20 @@ const MultiLevelSelect = (props: MultiLevelSelectProps) => {
</div>

{isDropdownClosed ? (
<div key="chevron-down">
<div id={arrowDownElementId}
key="chevron-down">
<Icon
icon="chevron-down"
id={arrowDownElementId}
size="xs"
/>
</div>
) : (
<div key="chevron-up">
<div id={arrowUpElementId}
key="chevron-up">
<Icon
icon="chevron-up"
id={arrowUpElementId}
size="xs"
/>
</div>
Expand Down

0 comments on commit 5c8575d

Please sign in to comment.