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

Small improvements to MarkdownEditor component #2236

Merged
merged 8 commits into from
Aug 23, 2022

Conversation

iansan5653
Copy link
Contributor

@iansan5653 iansan5653 commented Aug 16, 2022

This has some minor followup changes to #2182:

  • Adds Ctrl+Shift+P (Cmd+Shift+P on Mac) shortcut for toggling between edit & preview mode. This was a little trickier than I expected - toggling to preview mode is easy because we can add the listener to the input, but listening for the shortcut to go back to edit mode requires a global listener (because there is no visible input to focus). When we do that, we have to maintain a global stack of editors in the order they've switched to preview mode in case multiple editors are mounted at once.
  • Limits the type of the Ref passed to MarkdownEditor so that consumers cannot accidentally create the ref using useRef<HTMLTextAreaElement>. This was possible before because HTMLElement was assignable to MarkdownEditorHandle, so I added a fake symbol 'brand' key to disallow this. It's somewhat hacky but worth it to prevent a very common mistake.
  • Fixes the prop names in examples in the MarkdownViewer docs so the examples will render (they are erroring with TypeError: Cannot read properties of undefined (reading '__html')).

This fixes #2231, except for erroring when there is no Label present - I tried to fix this but it's very hard to do with the current implementation of slots. I think it's not worth the extra lift right now.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

@iansan5653 iansan5653 requested a review from a team August 16, 2022 20:58
@iansan5653 iansan5653 self-assigned this Aug 16, 2022
@changeset-bot
Copy link

changeset-bot bot commented Aug 16, 2022

🦋 Changeset detected

Latest commit: d62f317

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

This PR includes changesets to release 1 package
Name Type
@primer/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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 16, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 75.62 KB (0%)
dist/browser.umd.js 76.23 KB (0%)

@iansan5653 iansan5653 temporarily deployed to github-pages August 16, 2022 21:09 Inactive
Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Scoped to drafts, pretty safe. Trust Ian on the implementation details

@iansan5653 iansan5653 enabled auto-merge (squash) August 23, 2022 14:25
@iansan5653 iansan5653 temporarily deployed to github-pages August 23, 2022 14:31 Inactive
@iansan5653 iansan5653 merged commit 8cc0efe into main Aug 23, 2022
@iansan5653 iansan5653 deleted the improve-markdown-editor branch August 23, 2022 14:33
@primer-css primer-css mentioned this pull request Aug 23, 2022
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.

MarkdownEditor followup work
2 participants