Skip to content

Commit

Permalink
Changes to how the ref works.
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerBroyles committed Sep 28, 2023
1 parent 890507b commit d599b9e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions client/app/components/SearchableDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import Select, { components } from 'react-select';
import AsyncSelect from 'react-select/async';
import CreatableSelect from 'react-select/creatable';
import _, { isPlainObject, isNull, kebabCase, isEmpty, isString } from 'lodash';
import { isPlainObject, isNull, kebabCase, isEmpty, isString, differenceWith, trim, isEqual } from 'lodash';
import classNames from 'classnames';
import { css } from 'glamor';
import { FormLabel } from './FormLabel';
Expand Down Expand Up @@ -87,7 +87,7 @@ export const SearchableDropdown = (props) => {
const onClickOutside = (event) => {
// event.composedPath() is [html, document, Window] when clicking the scroll bar and more when clicking content
// this stops the menu from closing if a user clicks to use the scroll bar with the menu open
if ((wrapperRef && !wrapperRef.contains(event.target) &&
if ((wrapperRef && !wrapperRef.current.contains(event.target) &&
event.composedPath()[2] !== window && isExpanded)) {
// this.setState({
// isExpanded: true
Expand All @@ -112,11 +112,10 @@ export const SearchableDropdown = (props) => {
};
}, [isExpanded]);

// eslint-disable-next-line camelcase
// UNSAFE_componentWillReceiveProps = (nextProps) => {
// console.log('in UNSAFE_will receive props');
// this.setState({ value: nextProps.value });
// };
useEffect(() => {
// Update state when props.value changes
setStateValue(props.value);
}, [props.value]);

// componentDidUpdate(prevProps) {
// if (prevProps.value !== this.props.value) {
Expand Down Expand Up @@ -171,7 +170,7 @@ export const SearchableDropdown = (props) => {
Array.isArray(stateValue) &&
newValue.length < stateValue.length
) {
deletedValue = _.differenceWith(stateValue, newValue, _.isEqual);
deletedValue = differenceWith(stateValue, newValue, isEqual);
}
if (onChange) {
onChange(newValue, deletedValue);
Expand Down Expand Up @@ -271,7 +270,7 @@ export const SearchableDropdown = (props) => {
// eslint-disable-next-line no-shadow
isValidNewOption: (inputValue) => inputValue && (/\S/).test(inputValue),

formatCreateLabel: (tagName) => `Create a tag for "${_.trim(tagName)}"`,
formatCreateLabel: (tagName) => `Create a tag for "${trim(tagName)}"`,

...creatableOptions,
};
Expand Down

0 comments on commit d599b9e

Please sign in to comment.