Skip to content

Commit

Permalink
feat: mount scrollTo on ref (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
atzcl authored Dec 28, 2020
1 parent b035c9f commit 773c312
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 @@ -46,6 +47,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 @@ -58,6 +59,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 @@ -369,6 +371,7 @@ export default function generateSelector<
React.useImperativeHandle(ref, () => ({
focus: selectorRef.current.focus,
blur: selectorRef.current.blur,
scrollTo: listRef.current?.scrollTo,
}));

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

1 comment on commit 773c312

@vercel
Copy link

@vercel vercel bot commented on 773c312 Dec 28, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.