Skip to content

Commit

Permalink
Closes a dropdown list when the placeholder line is clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
curlyfriesplease committed Nov 25, 2024
1 parent db786fa commit 6d58256
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Container,
Dropdown,
DropdownList,
DropdownItem,
DropdownItemSelectable,
TextItalic
} from './TextInputWithDropdown.style';
Expand Down Expand Up @@ -66,6 +65,12 @@ const TextInputWithDropdown = React.forwardRef(
};
}, [options.length, forceClosed, onChange]);

const closeDropdown = () => {
console.log('handleDropdownInstructionClick');

Check warning on line 69 in src/components/Atoms/TextInputWithDropdown/TextInputWithDropdown.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected console statement
setForceClosed(true);
setActiveOption(-1);
};

// Reset forceClosed when options change
useEffect(() => {
setForceClosed(false);
Expand Down Expand Up @@ -112,6 +117,7 @@ const TextInputWithDropdown = React.forwardRef(
onSelect,
dropdownInstruction,
activeOption,
closeDropdown,
resetActiveOption: () => setActiveOption(-1)
};

Expand Down Expand Up @@ -144,6 +150,7 @@ const Options = React.forwardRef(({
dropdownInstruction,
onSelect,
activeOption,
closeDropdown,
resetActiveOption,
...rest
}, ref) => {
Expand All @@ -170,9 +177,16 @@ const Options = React.forwardRef(({
}
>
{dropdownInstruction && (
<DropdownItem role="option">
<TextItalic>{dropdownInstruction}</TextItalic>
</DropdownItem>
<DropdownItemSelectable
id="dropdown-instruction"
role="option"
key="dropdown-instruction"
onClick={closeDropdown}
>
<TextItalic>
{dropdownInstruction}
</TextItalic>
</DropdownItemSelectable>
)}
{options.map((option, index) => (
<DropdownItemSelectable
Expand Down Expand Up @@ -220,7 +234,8 @@ Options.propTypes = {
dropdownInstruction: PropTypes.string,
activeOption: PropTypes.number.isRequired,
resetActiveOption: PropTypes.func.isRequired,
hideBorder: PropTypes.bool
hideBorder: PropTypes.bool,
closeDropdown: PropTypes.func.isRequired
};

TextInputWithDropdown.displayName = 'TextInputWithDropdown';
Expand Down

0 comments on commit 6d58256

Please sign in to comment.