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

Fix #3662: Dropdown add focusInputRef for React Hook Form #3663

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions components/doc/dropdown/apidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ export function ApiDoc(props) {
<td>null</td>
<td>Identifier of the focusable input.</td>
</tr>
<tr>
<td>focusInputRef</td>
<td>Ref</td>
<td>null</td>
<td>Ref of the focusable input.</td>
</tr>
<tr>
<td>showClear</td>
<td>boolean</td>
Expand Down
6 changes: 4 additions & 2 deletions components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const Dropdown = React.memo(
const elementRef = React.useRef(null);
const overlayRef = React.useRef(null);
const inputRef = React.useRef(props.inputRef);
const focusInputRef = React.useRef(null);
const focusInputRef = React.useRef(props.focusInputRef);
const searchTimeout = React.useRef(null);
const searchValue = React.useRef(null);
const currentSearchChar = React.useRef(null);
Expand Down Expand Up @@ -590,7 +590,8 @@ export const Dropdown = React.memo(

React.useEffect(() => {
ObjectUtils.combinedRefs(inputRef, props.inputRef);
}, [inputRef, props.inputRef]);
ObjectUtils.combinedRefs(focusInputRef, props.focusInputRef);
}, [inputRef, props.inputRef, focusInputRef, props.focusInputRef]);

useMountEffect(() => {
if (props.autoFocus) {
Expand Down Expand Up @@ -809,6 +810,7 @@ Dropdown.defaultProps = {
filterMatchMode: 'contains',
filterPlaceholder: null,
filterTemplate: null,
focusInputRef: null,
id: null,
inputId: null,
inputRef: null,
Expand Down
77 changes: 39 additions & 38 deletions components/lib/dropdown/dropdown.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import TooltipOptions from '../tooltip/tooltipoptions';
import { CSSTransitionProps } from '../csstransition';
import { VirtualScrollerProps } from '../virtualscroller';
import { SelectItemOptionsType } from '../selectitem/selectitem';
import TooltipOptions from '../tooltip/tooltipoptions';
import { VirtualScrollerProps } from '../virtualscroller';

type DropdownOptionGroupTemplateType = React.ReactNode | ((option: any, index: number) => React.ReactNode);

Expand Down Expand Up @@ -45,54 +45,56 @@ interface DropdownFilterOptions {
}

export interface DropdownProps extends Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLDivElement>, HTMLDivElement>, 'onChange' | 'ref'> {
appendTo?: DropdownAppendToType;
ariaLabel?: string;
ariaLabelledBy?: string;
autoFocus?: boolean;
children?: React.ReactNode;
className?: string;
dataKey?: string;
disabled?: boolean;
dropdownIcon?: string;
editable?: boolean;
emptyFilterMessage?: DropdownEmptyFilterMessageType;
emptyMessage?: DropdownEmptyMessageType;
filter?: boolean;
filterBy?: string;
filterInputAutoFocus?: boolean;
filterLocale?: string;
filterMatchMode?: string;
filterPlaceholder?: string;
filterTemplate?: DropdownFilterTemplateType;
focusInputRef?: React.Ref<HTMLInputElement>;
id?: string;
inputId?: string;
inputRef?: React.Ref<HTMLSelectElement>;
itemTemplate?: DropdownItemTemplateType;
maxLength?: number;
name?: string;
value?: any;
options?: SelectItemOptionsType;
optionLabel?: string;
optionValue?: string;
optionDisabled?: DropdownOptionDisabledType;
optionGroupLabel?: string;
optionGroupChildren?: string;
optionGroupLabel?: string;
optionGroupTemplate?: DropdownOptionGroupTemplateType;
valueTemplate?: DropdownValueTemplateType;
filterTemplate?: DropdownFilterTemplateType;
itemTemplate?: DropdownItemTemplateType;
style?: React.CSSProperties;
className?: string;
virtualScrollerOptions?: VirtualScrollerProps;
scrollHeight?: string;
filter?: boolean;
filterBy?: string;
filterMatchMode?: string;
filterPlaceholder?: string;
filterLocale?: string;
emptyMessage?: DropdownEmptyMessageType;
emptyFilterMessage?: DropdownEmptyFilterMessageType;
editable?: boolean;
optionLabel?: string;
optionValue?: string;
options?: SelectItemOptionsType;
panelClassName?: string;
panelStyle?: React.CSSProperties;
placeholder?: string;
required?: boolean;
disabled?: boolean;
appendTo?: DropdownAppendToType;
tabIndex?: number;
autoFocus?: boolean;
filterInputAutoFocus?: boolean;
resetFilterOnHide?: boolean;
showFilterClear?: boolean;
panelClassName?: string;
panelStyle?: React.CSSProperties;
dataKey?: string;
inputId?: string;
scrollHeight?: string;
showClear?: boolean;
maxLength?: number;
showFilterClear?: boolean;
showOnFocus?: boolean;
style?: React.CSSProperties;
tabIndex?: number;
tooltip?: string;
tooltipOptions?: TooltipOptions;
ariaLabel?: string;
ariaLabelledBy?: string;
transitionOptions?: CSSTransitionProps;
dropdownIcon?: string;
showOnFocus?: boolean;
value?: any;
valueTemplate?: DropdownValueTemplateType;
virtualScrollerOptions?: VirtualScrollerProps;
onChange?(e: DropdownChangeParams): void;
onFocus?(event: React.FocusEvent<HTMLInputElement>): void;
onBlur?(event: React.FocusEvent<HTMLInputElement>): void;
Expand All @@ -101,7 +103,6 @@ export interface DropdownProps extends Omit<React.DetailedHTMLProps<React.InputH
onShow?(): void;
onHide?(): void;
onFilter?(e: DropdownFilterParams): void;
children?: React.ReactNode;
}

export declare class Dropdown extends React.Component<DropdownProps, any> {
Expand Down