Skip to content

Commit

Permalink
fix(Picker): pass name prop to underlying input element (#3275)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Jul 5, 2023
1 parent f673c85 commit 3b7cce5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Picker/PickerToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface PickerToggleProps extends ToggleButtonProps {

// Renders an input and is editable
editable?: boolean;
name?: string;
inputPlaceholder?: string;
inputMask?: (string | RegExp)[];
onInputChange?: (value: string, event: React.ChangeEvent) => void;
Expand Down Expand Up @@ -85,6 +86,7 @@ const PickerToggle: RsRefForwardingComponent<typeof ToggleButton, PickerTogglePr
caretComponent,
caretAs = caretComponent,
label,
name,
...rest
} = props;

Expand Down Expand Up @@ -189,11 +191,12 @@ const PickerToggle: RsRefForwardingComponent<typeof ToggleButton, PickerTogglePr
(ref, props) => (
<input
ref={mergeRefs(inputRef, ref)}
name={name}
style={{ pointerEvents: editable ? undefined : 'none' }}
{...props}
/>
),
[editable]
[editable, name]
);

const ToggleCaret = useToggleCaret(placement);
Expand Down
7 changes: 7 additions & 0 deletions src/Picker/test/PickerToggleSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ describe('<PickerToggle>', () => {
assert.equal(instance.textContent, Title);
});

it('Should render a hidden <input> element with given "name" attribute', () => {
const { container } = render(<Toggle name="field" />);

// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('input')).to.have.attr('name', 'field');
});

describe('Cleanable (`cleanable`=true)', () => {
it('Should render a clear button when value is present', () => {
render(
Expand Down
3 changes: 2 additions & 1 deletion src/Picker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ export function usePickerClassName(props: PickerClassNameProps): [string, string
})
);

// Those props that're used for composing the className
const usedClassNamePropKeys = Object.keys(
omit(props, [...Object.keys(rest || {}), 'disabled', 'readOnly', 'plaintext'])
omit(props, [...Object.keys(rest || {}), 'disabled', 'readOnly', 'plaintext', 'name'])
);

return [classes, usedClassNamePropKeys];
Expand Down
7 changes: 7 additions & 0 deletions src/SelectPicker/test/SelectPickerSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ describe('SelectPicker', () => {
expect(instance).to.have.class('rs-picker-disabled');
});

it('Should render a hidden <input> with given "name" attribute', () => {
const { container } = render(<SelectPicker data={[]} name="field" />);

// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
expect(container.querySelector('input')).to.have.attr('name', 'field');
});

describe('Loading state', () => {
it('Should display a spinner when loading=true', () => {
render(<SelectPicker data={data} loading />);
Expand Down

1 comment on commit 3b7cce5

@vercel
Copy link

@vercel vercel bot commented on 3b7cce5 Jul 5, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

rsuite-nextjs – ./docs

rsuite-nextjs-git-main-rsuite.vercel.app
rsuitejs.com
rsuite.vercel.app
rsuite-nextjs-rsuite.vercel.app

Please sign in to comment.