-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(query-builder): Allow pasting without requiring user permissions #74054
feat(query-builder): Allow pasting without requiring user permissions #74054
Conversation
const {size} = useSearchQueryBuilder(); | ||
const {state, gridProps} = useQueryBuilderGrid(props, ref); | ||
|
||
const state = useListState<ParseResultToken>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to move some things around to pass the undo
function into the new component.
@@ -17,59 +13,26 @@ interface UseQueryBuilderGridProps extends AriaGridListOptions<ParseResultToken> | |||
|
|||
const noop = () => {}; | |||
|
|||
function findNearestFreeTextKey( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the changes in this file are moving the onKeyDown logic from here to the new component
Bundle ReportChanges will increase total bundle size by 2.0kB ⬆️
|
undo: () => void; | ||
}; | ||
|
||
function findNearestFreeTextKey( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is unchanged from the file it was moved from
[dispatch, selectedTokens] | ||
); | ||
|
||
const onKeyDown = useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All this logic is copied over from useQueryBuilderGrid
, the only new part of this component is the rendered input and the onPaste
handler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Currently when there is a selection, the focus is on the top-level grid div (because there is nowhere else for the focus to go). We have been listening for keydown events here, which works for everything except pasting, because divs do not have the
onPaste
event. Currently we are accessing the clipboard withnavigator.clipboard.readText()
, but that requires the user to grant permission which is not a good experience.To solve this, we now render an invisible input within the grid (
<SelectionKeyHandler />
), which receives focus when there is a selection. Since this input needs to handle the paste event, I also moved all the selection-specific keydown logic there as well.