Skip to content

Commit

Permalink
amitha/feature/combobox-prevent-scroll (#299)
Browse files Browse the repository at this point in the history
* add scroll prevention

* move to defaults
  • Loading branch information
amit-hanoch authored Oct 25, 2021
1 parent 23e6a3a commit 550c7e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/components/Combobox/Combobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const Combobox = forwardRef(
onFilterChanged,
loading,
onOptionHover,
onOptionLeave
onOptionLeave,
shouldScrollToSelectedItem
},
ref
) => {
Expand Down Expand Up @@ -104,6 +105,7 @@ const Combobox = forwardRef(
onOptionHover={onOptionEnter}
onOptionLeave={onOptionLeave}
optionLineHeight={optionLineHeight}
shouldScrollWhenActive={shouldScrollToSelectedItem}
/>
);
index++;
Expand Down Expand Up @@ -237,7 +239,8 @@ Combobox.propTypes = {
onFilterChanged: PropTypes.func,
loading: PropTypes.bool,
onOptionHover: PropTypes.func,
onOptionLeave: PropTypes.func
onOptionLeave: PropTypes.func,
shouldScrollToSelectedItem: PropTypes.bool
};
Combobox.defaultProps = {
className: "",
Expand All @@ -259,7 +262,8 @@ Combobox.defaultProps = {
/** shows loading animation */
loading: false,
onOptionHover: NOOP,
onOptionLeave: NOOP
onOptionLeave: NOOP,
shouldScrollToSelectedItem: true
};

export default Combobox;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const ComboboxOption = ({
onOptionClick,
onOptionLeave,
onOptionHover,
optionLineHeight
optionLineHeight,
shouldScrollWhenActive
}) => {
const {
id,
Expand All @@ -35,7 +36,7 @@ const ComboboxOption = ({

useEffect(() => {
const element = ref.current;
if (isActive && element) {
if (isActive && element && shouldScrollWhenActive) {
element.scrollIntoView({ behaviour: "smooth" });
}
}, [ref, isActive]);
Expand Down Expand Up @@ -115,4 +116,8 @@ ComboboxOption.iconTypes = {
RENDERER: "renderer"
};

ComboboxOption.defaultProps = {
shouldScrollWhenActive: true
};

export default ComboboxOption;

0 comments on commit 550c7e4

Please sign in to comment.