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

Capture element selections through useSelected #4365

Merged
merged 6 commits into from
Aug 12, 2021

Conversation

samarsault
Copy link
Contributor

@samarsault samarsault commented Jul 6, 2021

Description
Element selections were not captured by the useSelected hook

Issue
Fixes: #4338

Example (Before)

Borrowed from #4338.
Code - https://jsfiddle.net/4c21gd5v/22/

before-selection

Example (After)

after-selection

Context
From the code, It seems like the Element does not have access to the SelectedContext, but all elements inside it do. So instead of inside the Element, I wrapped the SelectionContext around the element as following:

<SelectedContext.Provider value={!!sel}>
  <ElementComponent
      ...
  />
</SelectedContext.Provider>

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Jul 6, 2021

🦋 Changeset detected

Latest commit: 7ae7bd5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

@cboppert cboppert left a comment

Choose a reason for hiding this comment

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

Looks good to me, will leave up to @BrentFarese or @timbuckley for a final approval

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

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

Apologies @samarsault , there's a merge conflict from a PR we landed yesterday. Could you please rebase when you have a moment. Also if you could create a changeset (see the comment in the PR) then I'll go ahead and merge into main. Thanks!

@dylans dylans merged commit 906e5af into ianstormtaylor:main Aug 12, 2021
@github-actions github-actions bot mentioned this pull request Aug 12, 2021
@dylans dylans mentioned this pull request Sep 11, 2021
dylans pushed a commit to dylans/slate that referenced this pull request Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useSelected does not work for non-void Elements.
4 participants