Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for undo a null check which cause weird behavior (combobox) #635

Merged
merged 4 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`BreadcrumbsItem renders correctly when disabled item 1`] = `
<span
aria-disabled="true"
className="breadcrumb-content disabled"
tabIndex="0"
tabIndex="-1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for fix snapshot tests

>
<span
className="breadcrumb-text"
Expand Down
7 changes: 6 additions & 1 deletion src/components/Combobox/Combobox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ const Combobox = forwardRef(
optionRenderer,
renderOnlyVisibleOptions,
clearFilterOnSelection,
maxOptionsWithoutScroll
maxOptionsWithoutScroll,
/**
* temporary flag for investigate a bug - will remove very soon
*/
forceUndoScrollNullCheck = false
},
ref
) => {
Expand Down Expand Up @@ -195,6 +199,7 @@ const Combobox = forwardRef(
/>
{stickyCategories && <StickyCategoryHeader label={activeCategoryLabel} />}
<ComboboxItems
forceUndoScrollNullCheck={forceUndoScrollNullCheck}
categories={categories}
options={filteredOptions}
filterValue={filterValue}
Expand Down
1 change: 1 addition & 0 deletions src/components/Combobox/__stories__/combobox.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ better user experience.
<Combobox
options={options}
renderOnlyVisibleOptions
forceUndoScrollNullCheck
placeholder="Placeholder text here"
maxOptionsWithoutScroll={3}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const ComboboxItems = ({
shouldScrollToSelectedItem,
renderOnlyVisibleOptions,
onActiveCategoryChanged,
maxOptionsWithoutScroll
maxOptionsWithoutScroll,
forceUndoScrollNullCheck
}) => {
const activeCategoryId = useRef();

Expand Down Expand Up @@ -56,7 +57,8 @@ export const ComboboxItems = ({
optionRenderer,
isActiveByKeyboard,
activeItemIndex,
shouldScrollToSelectedItem
shouldScrollToSelectedItem,
forceUndoScrollNullCheck
},
isVirtualized: renderOnlyVisibleOptions
}),
Expand All @@ -69,6 +71,7 @@ export const ComboboxItems = ({
isActiveByKeyboard,
activeItemIndex,
shouldScrollToSelectedItem,
forceUndoScrollNullCheck,
renderOnlyVisibleOptions
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const ComboboxOption = ({
onOptionHover,
optionLineHeight,
shouldScrollWhenActive,
optionRenderer
optionRenderer,
/**
* temporary flag for investigate a bug - will remove very soon
*/
forceUndoScrollNullCheck = false
}) => {
const {
id,
Expand All @@ -41,9 +45,13 @@ const ComboboxOption = ({
useEffect(() => {
const element = ref.current;
if (isActive && element && shouldScrollWhenActive) {
element.scrollIntoView?.({ behaviour: "smooth" });
if (forceUndoScrollNullCheck) {
element?.scrollIntoView({ behaviour: "smooth" });
} else {
element.scrollIntoView?.({ behaviour: "smooth" });
}
}
}, [ref, isActive, shouldScrollWhenActive]);
}, [ref, isActive, shouldScrollWhenActive, forceUndoScrollNullCheck]);

const renderIcon = (icon, iconType, className) => {
if (iconType === ComboboxOption.iconTypes.RENDERER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export function optionItemRenderer({
shouldScrollToSelectedItem,
activeItemIndex,
belongToCategory,
isActiveByKeyboard
isActiveByKeyboard,
forceUndoScrollNullCheck
}) {
return (
<ComboboxOption
Expand All @@ -130,6 +131,7 @@ export function optionItemRenderer({
optionLineHeight={optionLineHeight}
belongToCategory={belongToCategory}
shouldScrollWhenActive={shouldScrollToSelectedItem}
forceUndoScrollNullCheck={forceUndoScrollNullCheck}
/>
);
}