Skip to content

Commit 3bc55b2

Browse files
authored
Merge pull request #1231 from buildo/1230-dropdown_fix_ref_error
#1230: Dropdown: Fix ref error when testing with Enzyme (closes #1230)
2 parents 8ccd9f3 + b15ad14 commit 3bc55b2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Dropdown/Dropdown.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ const defaultOptionGroupRenderer = (title: string) => title;
1919

2020
const defaultMenuRenderer: Dropdown.MenuRendererHandler = ({
2121
focusedOption,
22+
focusOption,
2223
instancePrefix,
2324
onFocus,
25+
onOptionRef,
2426
onSelect,
2527
groupByKey,
2628
optionClassName,
@@ -63,7 +65,6 @@ const defaultMenuRenderer: Dropdown.MenuRendererHandler = ({
6365
{optionGroup.map((option, i) => {
6466
const isSelected = valueArray && valueArray.indexOf(option) > -1;
6567
const isFocused = option === focusedOption;
66-
const optionRef = isFocused ? 'focused' : null;
6768
const optionClass = cx(optionClassName, {
6869
'Select-option': true,
6970
'is-selected': isSelected,
@@ -73,6 +74,7 @@ const defaultMenuRenderer: Dropdown.MenuRendererHandler = ({
7374
return (
7475
<OptionComponent
7576
className={optionClass}
77+
focusOption={focusOption}
7678
instancePrefix={instancePrefix}
7779
isDisabled={option.disabled}
7880
isFocused={isFocused}
@@ -82,7 +84,7 @@ const defaultMenuRenderer: Dropdown.MenuRendererHandler = ({
8284
onSelect={onSelect}
8385
option={option}
8486
optionIndex={i}
85-
ref={optionRef}
87+
ref={(ref: React.Component<Dropdown.Props> | null) => { onOptionRef(ref, isFocused); }}
8688
>
8789
{optionRenderer(option, i)}
8890
</OptionComponent>
@@ -213,6 +215,7 @@ export namespace Dropdown {
213215
// seem supported by react-select but missing in the @types file?
214216
instancePrefix?: string
215217
onFocus?: () => void
218+
onOptionRef: (ref: React.Component<Dropdown.Props> | null, isFocused: boolean) => void
216219
onSelect?: () => void
217220
optionClassName?: string
218221
optionComponent: React.ComponentType<{ [k: string]: any }> // TODO

0 commit comments

Comments
 (0)