Skip to content
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

Conversation

malwilley
Copy link
Member

@malwilley malwilley commented Jul 9, 2024

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 with navigator.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.

@malwilley malwilley requested a review from a team July 9, 2024 23:33
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jul 9, 2024
const {size} = useSearchQueryBuilder();
const {state, gridProps} = useQueryBuilderGrid(props, ref);

const state = useListState<ParseResultToken>({
Copy link
Member Author

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(
Copy link
Member Author

@malwilley malwilley Jul 9, 2024

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

Copy link

codecov bot commented Jul 9, 2024

Bundle Report

Changes will increase total bundle size by 2.0kB ⬆️

Bundle name Size Change
app-webpack-bundle-array-push 27.3MB 2.0kB ⬆️

undo: () => void;
};

function findNearestFreeTextKey(
Copy link
Member Author

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(
Copy link
Member Author

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

Copy link
Member

@roggenkemper roggenkemper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@malwilley malwilley merged commit f36355e into master Jul 10, 2024
44 checks passed
@malwilley malwilley deleted the malwilley/feat/search-query-builder-paste-without-permissions branch July 10, 2024 22:45
@github-actions github-actions bot locked and limited conversation to collaborators Jul 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Frontend Automatically applied to PRs that change frontend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants