Skip to content

Commit

Permalink
scroll to category. fixes #46
Browse files Browse the repository at this point in the history
  • Loading branch information
slaurent22 committed Oct 5, 2021
1 parent f51dac4 commit 66f6167
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/components/CategorySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ const customStyles: StylesConfig<CategoryOption> = {
},
};

// https://stackoverflow.com/a/66710895
const onMenuOpen = () => {
setTimeout(()=>{
const selectedEl = document.getElementsByClassName("MyDropdown__option--is-selected")[0];
if (selectedEl) {
selectedEl.scrollIntoView({ behavior: "smooth", block: "center", });
}
}, 15);
};

function defToOption({ fileName, displayName, }: CategoryDefinition): CategoryOption {
return {
value: fileName, label: displayName,
Expand Down Expand Up @@ -76,6 +86,9 @@ const CategorySelect: React.FC<Props> = ({
options={optGroups}
styles={customStyles}
onChange={newValue => onChange(newValue ? optionToDef(newValue) : null)}
onMenuOpen={onMenuOpen}
className ={"MyDropdown"}
classNamePrefix={"MyDropdown"}
placeholder="Category: Select or type to search..."
theme={theme => ({
...theme,
Expand Down

0 comments on commit 66f6167

Please sign in to comment.