Skip to content

Commit ce895db

Browse files
authored
fix: breakline of seprator (#589)
* fix: br logic * fix: Test case
1 parent c921110 commit ce895db

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Selector/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
185185
// Pasted text should replace back to origin content
186186
if (tokenWithEnter && pastedTextRef.current && /[\r\n]/.test(pastedTextRef.current)) {
187187
// CRLF will be treated as a single space for input element
188-
const replacedText = pastedTextRef.current.replace(/\r\n/g, ' ').replace(/[\r\n]/g, ' ');
188+
const replacedText = pastedTextRef.current
189+
.replace(/[\r\n]+$/, '')
190+
.replace(/\r\n/g, ' ')
191+
.replace(/[\r\n]/g, ' ');
189192
value = value.replace(replacedText, pastedTextRef.current);
190193
}
191194

tests/Tags.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('Select.Tags', () => {
154154
{
155155
tokenSeparators: ['\r\n'],
156156
clipboardText: '\r\nlight\r\nbamboo\r\n',
157-
inputValue: ' light bamboo ',
157+
inputValue: ' light bamboo',
158158
},
159159
{
160160
tokenSeparators: [' ', '\r\n'],
@@ -164,7 +164,7 @@ describe('Select.Tags', () => {
164164
{
165165
tokenSeparators: ['\n'],
166166
clipboardText: '\nlight\nbamboo\n',
167-
inputValue: ' light bamboo ',
167+
inputValue: ' light bamboo',
168168
},
169169
].forEach(({ tokenSeparators, clipboardText, inputValue }) => {
170170
it(`paste content to split (${JSON.stringify(tokenSeparators)})`, () => {

0 commit comments

Comments
 (0)