Skip to content

Commit

Permalink
feat: mount scrollTo on ref
Browse files Browse the repository at this point in the history
  • Loading branch information
atzcl committed Nov 17, 2020
1 parent 8edd430 commit 2bc2726
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import * as React from 'react';
import { useRef } from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import { ScrollTo } from 'rc-virtual-list/lib/List';
import MultipleSelector from './MultipleSelector';
import SingleSelector from './SingleSelector';
import { LabelValueType, RawValueType, CustomTagProps } from '../interface/generator';
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface InnerSelectorProps {
export interface RefSelectorProps {
focus: () => void;
blur: () => void;
scrollTo?: ScrollTo,
}

export interface SelectorProps {
Expand Down
3 changes: 3 additions & 0 deletions src/generate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useState, useRef, useEffect, useMemo } from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import classNames from 'classnames';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import { ScrollTo } from 'rc-virtual-list/lib/List';
import Selector, { RefSelectorProps } from './Selector';
import SelectTrigger, { RefTriggerProps } from './SelectTrigger';
import { RenderNode, Mode, RenderDOMFunc, OnActiveValue } from './interface';
Expand Down Expand Up @@ -57,6 +58,7 @@ const DEFAULT_OMIT_PROPS = [
export interface RefSelectProps {
focus: () => void;
blur: () => void;
scrollTo?: ScrollTo,
}

export interface SelectProps<OptionsType extends object[], ValueType> extends React.AriaAttributes {
Expand Down Expand Up @@ -365,6 +367,7 @@ export default function generateSelector<
React.useImperativeHandle(ref, () => ({
focus: selectorRef.current.focus,
blur: selectorRef.current.blur,
scrollTo: listRef.current?.scrollTo,
}));

// ============================= Value ==============================
Expand Down

0 comments on commit 2bc2726

Please sign in to comment.