Skip to content

Commit

Permalink
FIX Adding withForwardedRef HOC to EbaySelect (#298)
Browse files Browse the repository at this point in the history
* Adding withForwardedRef HOC to EbaySelect

* fixing lint issues

---------

Co-authored-by: Marcial Jimenez Caballero <[email protected]>
  • Loading branch information
marcial199545 and Marcial Jimenez Caballero authored Dec 14, 2023
1 parent b6c819d commit 92dd1f2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ebay-select/ebay-select.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { ChangeEvent, cloneElement, ComponentProps, FC, useState, useRef, FocusEvent } from 'react'
import React, { ChangeEvent, cloneElement, ComponentProps, FC, useState, FocusEvent } from 'react'
import classNames from 'classnames'
import EbaySelectOption from './ebay-select-option'
import { EbayIcon } from '../ebay-icon'
import { filterByType } from '../common/component-utils'
import { filterByType, withForwardRef } from '../common/component-utils'
import { useFloatingLabel } from '../common/floating-label-utils/hooks'
import { EbayChangeEventHandler } from '../common/event-utils/types'

Expand All @@ -15,6 +15,7 @@ export type EbaySelectProps = Omit<ComponentProps<'select'>, 'onChange'> & {
defaultValue?: SelectValue;
onChange?: EbayChangeEventHandler<HTMLSelectElement, ChangeEventProps>;
floatingLabel?: string;
forwardedRef?: React.Ref<HTMLSelectElement>;
inputSize?: 'default' | 'large';
invalid?: boolean;
};
Expand All @@ -30,22 +31,22 @@ const EbaySelect: FC<EbaySelectProps> = ({
onBlur = () => {},
onFocus = () => {},
floatingLabel,
forwardedRef,
children,
inputSize,
invalid,
...rest
}) => {
const isFieldInvalid = invalid || rest['aria-invalid'] === 'true'
const [value, setValue] = useState<SelectValue>(defaultValue)
const selectRef = useRef(null)
const {
label,
Container,
onBlur: onFloatingLabelBlur,
onFocus: onFloatingLabelFocus,
ref
} = useFloatingLabel({
ref: selectRef,
ref: forwardedRef,
inputId: rest.id,
className: className,
disabled: disabled,
Expand Down Expand Up @@ -102,7 +103,7 @@ const EbaySelect: FC<EbaySelectProps> = ({
)
}

export default EbaySelect
export default withForwardRef<EbaySelectProps>(EbaySelect)

function optionGroups(data) {
const optGroups = {}
Expand Down

0 comments on commit 92dd1f2

Please sign in to comment.