Skip to content

Commit

Permalink
feat(select): add select element ref
Browse files Browse the repository at this point in the history
for forms and other controlled focus cases

DSW-208
  • Loading branch information
ggougeon authored and gcornut committed Jun 19, 2024
1 parent 589309e commit f8373f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Chip`: fix forward key down event on clickable chip
- `TextField`: fix forward aria-describedby prop to input

### Changed

- `Select`, `SelectMultiple`: add `selectElementRef` prop to reference the actual input field of these components.

## [3.7.2][] - 2024-05-22

### Fixed
Expand Down
6 changes: 4 additions & 2 deletions packages/lumx-react/src/components/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { InputLabel } from '@lumx/react/components/input-label/InputLabel';

import { Comp } from '@lumx/react/utils/type';
import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
import { mergeRefs } from '@lumx/react/utils/mergeRefs';

import { WithSelectContext } from './WithSelectContext';
import { CoreSelectProps, SelectVariant } from './constants';
Expand Down Expand Up @@ -61,6 +62,7 @@ const SelectField: React.FC<SelectProps> = ({
theme,
value,
variant,
selectElementRef,
...forwardedProps
}) => {
return (
Expand All @@ -82,7 +84,7 @@ const SelectField: React.FC<SelectProps> = ({

{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
<div
ref={anchorRef as RefObject<HTMLDivElement>}
ref={mergeRefs(anchorRef as RefObject<HTMLDivElement>, selectElementRef)}
id={id}
className={`${CLASSNAME}__wrapper`}
onClick={onInputClick}
Expand Down Expand Up @@ -145,7 +147,7 @@ const SelectField: React.FC<SelectProps> = ({
after={<Icon icon={isEmpty ? mdiMenuDown : mdiCloseCircle} />}
onAfterClick={isEmpty ? onInputClick : onClear}
onClick={onInputClick}
ref={anchorRef as RefObject<HTMLAnchorElement>}
ref={mergeRefs(anchorRef as RefObject<HTMLAnchorElement>, selectElementRef)}
theme={theme}
{...forwardedProps}
>
Expand Down
6 changes: 4 additions & 2 deletions packages/lumx-react/src/components/select/SelectMultiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { InputLabel } from '@lumx/react/components/input-label/InputLabel';

import { Comp } from '@lumx/react/utils/type';
import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
import { mergeRefs } from '@lumx/react/utils/mergeRefs';

import { WithSelectContext } from './WithSelectContext';
import { CoreSelectProps, SelectVariant } from './constants';
Expand Down Expand Up @@ -75,6 +76,7 @@ export const SelectMultipleField: React.FC<SelectMultipleProps> = ({
theme,
value,
variant,
selectElementRef,
...forwardedProps
}) => (
<>
Expand All @@ -95,7 +97,7 @@ export const SelectMultipleField: React.FC<SelectMultipleProps> = ({

{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
<div
ref={anchorRef as RefObject<HTMLDivElement>}
ref={mergeRefs(anchorRef as RefObject<HTMLDivElement>, selectElementRef)}
id={id}
className={`${CLASSNAME}__wrapper`}
onClick={onInputClick}
Expand Down Expand Up @@ -150,7 +152,7 @@ export const SelectMultipleField: React.FC<SelectMultipleProps> = ({
after={<Icon icon={isEmpty ? mdiMenuDown : mdiCloseCircle} />}
onAfterClick={isEmpty ? onInputClick : onClear}
onClick={onInputClick}
ref={anchorRef as RefObject<HTMLAnchorElement>}
ref={mergeRefs(anchorRef as RefObject<HTMLAnchorElement>, selectElementRef)}
theme={theme}
{...forwardedProps}
>
Expand Down

0 comments on commit f8373f4

Please sign in to comment.