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
Add optional bottom guard for rendering suggestion list #339
Conversation
Codecov Report
@@ Coverage Diff @@
## master #339 +/- ##
=========================================
- Coverage 76.82% 76.8% -0.03%
=========================================
Files 22 22
Lines 630 638 +8
Branches 95 98 +3
=========================================
+ Hits 484 490 +6
- Misses 145 147 +2
Partials 1 1
Continue to review full report at Codecov.
|
@frontendphil @jfschwarz it seems like there's some kind of permission issue with the CI. I don't think it's failing because of my changes. |
This looks good to me and I contributed the |
I no longer have an active project that this would be used in - but looking over the changes it seems like it would work as desired 👍 |
@jfschwarz Any chance we can get some feedback from you to get this on track to be merged? |
@hyan7 Looks like master has been updated since this PR was submitted and you'll need to merge the latest changes from master into your branch to resolve the merge conflict. Let me know if you would like a hand. |
update head
# Conflicts: # src/MentionsInput.js
This pull request is automatically deployed with Now. Latest deployment for this branch: https://react-mentions-git-fork-hyan7-add-bottom-guard.wolf-pack.now.sh |
FWIW I did some checking to confirm and getting the offsetHeight/Width of a component isn't possible in enzyme/jsdom per enzymejs/enzyme#1525. Then jsdom/jsdom#135 is the relevant issue in jsdom (used by enzyme) where offsetWidth/Height, etc. are not yet supported. So I don't think there is an obvious way to add a unit test with this since enzyme doesn't support. Would require cypress.io, or puppeteer something. |
@jfschwarz @frontendphil It would be great if you could review this PR and give guidance on any changes you deem necessary in order to get it merged. |
Thank you for this! Could you please add an example for this to our demo page (src/demo)? |
@jfschwarz Thanks for looking it over. I added an example. The |
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.
Ran demo locally and it worked.
@jfschwarz @frontendphil Demo page added by @hyan7 and I added an approval. Please reply and tell us how we can help keep this PR moving forward. |
@jfschwarz @frontendphil Anything we can do to keep this PR moving forward? |
All jobs are passed so could we please merge this PR? |
@jfschwarz @frontendphil Let me know if there is anything else that needs done to merge this feature. Happy to incorporate your feedback if you have it. |
Thank you for the reminder. I had different priorities the last week, but this looks good now and we can finally merge it. My apologies thank you, @hyan7 |
Adds an optional prop
allowSuggestionsAboveCursor
that if set totrue
, the suggestion list will render above the cursor if there is not enough space underneath.Repro steps:
I came across this problem because the text input with
react-mentions
for my app is positioned in the bottom-right corner of the screen. Using the suggestions portal, if the user attempted to @ mention something, the suggestions list will open up underneath the cursor, making the list unusable since it would be cut off by the bottom of the screen. I tried to position it absolutely like theadvanced example
, but then it would get cut off by the right side of the screen if I tried to @ mention multiple things on the same line since the text input is on the bottom-right and the absolute positioning will make theright guard
useless.I added the
allowSuggestionsAboveCursor
prop and code that checks the prop and the spacing around the component to see if there is enough space to render the suggestion list underneath the cursor (the default way), and if there is not enough space underneath but enough space above, the list will render above the cursor (by adjusting thetop
) given the prop is set to true.The PR resolves the whole issue since I added checks for both the
suggestionsPortal
mode and the default mode.I followed closely the coding convention of the file.
I did not add tests since I could not find any examples in the existing tests that tests rendering positions.
The changes should not affect other parts of the code base since the added prop makes it opt-in.
I did not add any extra test files or set up.
Please test that the rendering behavior is as expected.