[BUG] - v2 textarea doesn't allow spaces inside a Table row
When trying to type in the Textarea box, spaces are not allowed.
Anyone have any idea of what is going on here? It seems that text boxes allow spaces until placed inside a map or a dynamic table (which I'm guessing under the hood uses something similar). @ceastman-r7 included a simple, reproducible example in the linked Stackblitz.
It's similar to these bugs here https://github.com/nextui-org/nextui/issues/1405 and https://github.com/nextui-org/nextui/issues/1608. In my case, spacebar randomly stops working in a <textarea/> placed inside a <TableCell/> (https://github.com/nextui-org/nextui/issues/1608#issuecomment-1811629800)
Same with <Input />
Experiencing the same issue with Textarea, a regular gives the same issue for me. Installing latest version (^2.2.9) does not solve this. Using the Textarea and Input fields in a regular table structure works fine.
@BjornsBot are you saying the issue is happening when creating the text areas inside of a map too? But works fine when outside of a map? Or is it happening when a text area is inside of a NextUI <Table> element, but putting the same text area inside of a pure HTML table works? Assuming the second one?
I am experiencing the same bug. The textarea appears to recognize a spacebar press if:
- The spacebar press is the first input after selecting the textarea
- The spacebar press is the first input after pausing for ~1 second
- The previous input was a spacebar press
Otherwise it does not seem to recognize pressing the spacebar.
This issue is caused by useTypeSelect in @react-aria/selection:
/**
* Handles typeahead interactions with collections.
*/
export function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {
let {keyboardDelegate, selectionManager, onTypeSelect} = options;
let state = useRef({
search: '',
timeout: null
}).current;
let onKeyDown = (e: KeyboardEvent) => {
let character = getStringForKey(e.key);
if (!character || e.ctrlKey || e.metaKey || !e.currentTarget.contains(e.target as HTMLElement)) {
return;
}
// Do not propagate the Spacebar event if it's meant to be part of the search.
// When we time out, the search term becomes empty, hence the check on length.
// Trimming is to account for the case of pressing the Spacebar more than once,
// which should cycle through the selection/deselection of the focused item.
if (character === ' ' && state.search.trim().length > 0) {
e.preventDefault();
if (!('continuePropagation' in e)) {
e.stopPropagation();
}
}
state.search += character;
// Use the delegate to find a key to focus.
// Prioritize items after the currently focused item, falling back to searching the whole list.
let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
// If no key found, search from the top.
if (key == null) {
key = keyboardDelegate.getKeyForSearch(state.search);
}
if (key != null) {
selectionManager.setFocusedKey(key);
if (onTypeSelect) {
onTypeSelect(key);
}
}
clearTimeout(state.timeout);
state.timeout = setTimeout(() => {
state.search = '';
}, TYPEAHEAD_DEBOUNCE_WAIT_MS);
};
return {
typeSelectProps: {
// Using a capturing listener to catch the keydown event before
// other hooks in order to handle the Spacebar event.
onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
}
};
}
and the value of TYPEAHEAD_DEBOUNCE_WAIT_MS is exactly 1000, as @des5771 stated
Here's a workaround. You can create a dummy keyboardDelegate and pass it to <Table />. The key is this dummy can't have the prop getKeyForSearch. But this solution prevent user from navigating the table elements by keyboard and may also cause other trouble.
Same with
<Input />
Same with <Input/> inside <Table>
Any updates on this issue?
Input inside table has the same problem, if you wait 1 second for the keyboard cursor to blink, you can press space, if you do it too fast it doesn't write. How can we still have this error?
@BjornsBot are you saying the issue is happening when creating the text areas inside of a map too? But works fine when outside of a map? Or is it happening when a text area is inside of a NextUI
<Table>element, but putting the same text area inside of a pure HTML table works? Assuming the second one?
Yes, putting the elements inside a regular table works fine. I had to step away from using the NextUI Table, apart from in cases where I need the functionality, because it gave me so many troubles when combining them with any input type.
yo! this bugs killing me. any update?