Skip to content

Commit

Permalink
fix(AutoComplete): fix AutoComplete plaintext mode not working (#3436)
Browse files Browse the repository at this point in the history
* fix(AutoComplete): fix AutoComplete plaintext mode not working

* test(AutoComplete): add tests for default value
  • Loading branch information
simonguo committed Nov 3, 2023
1 parent a7618c7 commit 72b79e7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/AutoComplete/AutoComplete.tsx
Expand Up @@ -34,6 +34,7 @@ import {
} from '../@types/common';

import { transformData, shouldDisplay } from './utils';
import Plaintext from '../Plaintext';

export type ValueType = string;

Expand Down Expand Up @@ -118,6 +119,7 @@ const AutoComplete: PickerComponent<AutoCompleteProps> = React.forwardRef(
menuClassName,
id,
readOnly,
plaintext,
renderMenu,
renderMenuItem,
onSelect,
Expand Down Expand Up @@ -282,6 +284,14 @@ const AutoComplete: PickerComponent<AutoCompleteProps> = React.forwardRef(
);
};

if (plaintext) {
return (
<Plaintext ref={ref} localeKey="unfilled">
{typeof value === 'undefined' ? defaultValue : value}
</Plaintext>
);
}

return (
<PickerToggleTrigger
ref={triggerRef}
Expand Down
32 changes: 32 additions & 0 deletions src/AutoComplete/test/AutoCompleteSpec.tsx
Expand Up @@ -267,4 +267,36 @@ describe('AutoComplete', () => {
// eslint-disable-next-line testing-library/no-node-access
expect(screen.getByTestId('test').querySelector('input')).to.have.class('rs-input-lg');
});

describe('Plain text', () => {
it('Should render input value', () => {
render(
<div data-testid="content">
<AutoComplete value="Haha" data={[]} plaintext />
</div>
);

expect(screen.getByTestId('content')).to.have.text('Haha');
});

it('Should render input default value', () => {
render(
<div data-testid="content">
<AutoComplete defaultValue="Haha" data={[]} plaintext />
</div>
);

expect(screen.getByTestId('content')).to.have.text('Haha');
});

it('Should render "Unfilled" if value is empty', () => {
render(
<div data-testid="content">
<AutoComplete value="" data={[]} plaintext />
</div>
);

expect(screen.getByTestId('content')).to.have.text('Unfilled');
});
});
});

1 comment on commit 72b79e7

@vercel
Copy link

@vercel vercel bot commented on 72b79e7 Nov 3, 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.vercel.app
rsuitejs.com
rsuite-nextjs-git-main-rsuite.vercel.app
rsuite-nextjs-rsuite.vercel.app

Please sign in to comment.