react-trix
react-trix copied to clipboard
MergeTags dropdown doesn't close on removing @
If I type '@' the dropdown appears, and if I remove the '@', the dropdown is still there.
Yes good catch, the popup should also dismiss if we press the Escape key.
@dstpierre That's true. Let me know if you need any help with this.
@vinay0x sure feel free to fork and try to implement this if you want. This would be in src/react-trix.tsx
at line: 125:
// if we have a collapse selection
if (text && range[0] == range[1]) {
// if we have a merge tag mergeTagTrigger
if (props.mergeTags) {
// get the cursor position and compare the last character with our mergeTagTrigger
const lastChar = range[0] - 1;
if (lastChar >= 0 && lastChar < text.length) {
const trigger = text[lastChar];
for (let i = 0; i < props.mergeTags.length; i++) {
if (trigger == props.mergeTags[i].trigger) {
state.showMergeTags = true;
state.tags = props.mergeTags[i].tags;
this.setState(state);
break;
}
}
}
}
}
I would try to see if state.showMergeTags
is already true
and there's no trigger character anymore.
For the escape key, a new keypress event could be added setting the showMergeTags
to false and that should be enough for that part.
Let me know how it goes.