Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cypress/integration/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ describe("React Textarea Autocomplete", () => {
cy.get('[data-test="minChar"]').clear({ force: true });
});

it("minChar works correctly basned on the lenght of the trigger char", () => {
cy.get('[data-test="minChar"]').type("{uparrow}"); // set minChar to 1

cy.get(".rta__textarea").type("This is test ::");
cy.get(".rta__autocomplete").should("not.be.visible");

cy.get(".rta__textarea").type("This is test ::a");
cy.get(".rta__autocomplete").should("be.visible");

cy.get(".rta__textarea").type("This is test :");
cy.get(".rta__autocomplete").should("not.be.visible");

cy.get(".rta__textarea").type("This is test :a");
cy.get(".rta__autocomplete").should("be.visible");
});

it("basic test with keyboard", () => {
cy.get(".rta__textarea")
.type("This is test :ro{downarrow}{enter}")
Expand Down
3 changes: 2 additions & 1 deletion src/Textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ class ReactTextareaAutocomplete extends React.Component<
let lastToken = tokenMatch && tokenMatch[0];

let currentTrigger = (tokenMatch && tokenMatch[1]) || null;
const currentTriggerLength = currentTrigger ? currentTrigger.length - 1 : 0;

// with this approach we want to know if the user just inserted a new trigger sequence
const newTrigger = this.tokenRegExpEnding.exec(affectedTextareaValue);
Expand All @@ -751,7 +752,7 @@ class ReactTextareaAutocomplete extends React.Component<
the autocomplete
*/
if (
(!lastToken || lastToken.length <= minChar) &&
(!lastToken || lastToken.length <= minChar + currentTriggerLength) &&
// check if our current trigger disallows whitespace
((this.state.currentTrigger &&
!trigger[this.state.currentTrigger].allowWhitespace) ||
Expand Down