Position react-modal relative to an element in the background - javascript

I have an input box in my main App element (id= "inputBox") and a react-modal that pops up when some input is given to this input box(via onChange event).
I want to position the react-modal just below this input box when it pops open but am being unable to do so.
I have so far only been able to position it relative to the viewport by calculating the offset of the input box and accordingly setting the style.top/style.left of the modal overlay.
But this is causing some other problems,so I need to be able to set the position relative to the input box.
Any suggestions on how to do this will be highly appreciated.

I think you're creating something like a search dropdown where some results appear on users search query. The most simple solution I can think of is to create a new component and include the popup inside that so it will be relative to it no matter what.
Your component will need to have its own state

Related

Adjust top of div after load

I am currently using the Intersoft Webgrid 9 for a bunch of our pages. Some of the columns use the built in Calendar popup to edit the date.
The calendar is suppose to popup just under the textbox for editing. In Chrome, this works fine but in IE the popup shows up quite a bit above the textbox.
The calendar popup is a div that is added to the page when the calendar image is first clicked. After the initial click, the div remains on the page but either the visibility changes to hidden when no longer being used or the position changes based on the textbox being edited.
Since we are using Intersoft's resources, I do not have direct access to the javascript for the image click event. I have however been able to add an additional click event to the calendar image but it fires before the div is drawn. After that since the div is now on the page, I am able to adjust the top of the div with jquery through this click event.
So I guess if anyone knows of a way to adjust the calendar control through Intersoft's built in javascript that would be great. Otherwise, I guess I was wondering if there was a way to adjust the top of the div after it has initially been added to the page.
I have attached two images.
Incorrectly displayed
Correctly displayed in Chrome
Thank you so much in advance for any help!
Is the text input element which the calendar is appended to relative or absolute positioned? If the calendar is being positioned absolutely then its parent needs to have relative positioning in order to work as expected. If you append an child with absolute positioning to an element with absolute positioning then they will both use the closest parent with relative positioning to calculate where they should be rendered.

HTML element offset change detect using jQuery

I am creating a custom dropdown control and facing issue with the value popup position.
When I scrolling the page/parent div , the base input box position got changed, if value popup is open , then it not changing the position at all.
I have added window scroll event, but its not triggering as, scroll is happening in div level.
Again that div is made dynamically, so don't have direct access to that.
If there are any way to detect my base input box position changed, so that I can handle this problem.

Select text in contenteditable after it has changed

I am about to write a input system for a web application that is a bit more complex. We have Labels in our text that are weather displayed as a bootstrap label (when the contenteditable div is blured) or displayed as handlebars e.g. {{firstname}} when the text is focused.
The changing in states is done by jQueries $().html(content) where I change the content based on the source when I focus the text field.
The problem is: if I click the text, I don't want to need to click a second time to place the cursor, because the text changed. It works as long I don't click inside of a tag but inside the contenteditable root element. but if I click inside of a tag inside the contenteditable, the cursor is not set.
my idea was to get the mouse position when clicking the contenteditable and then set the text cursor to exact that position when I have changed the text. But while I know, how I set the cursor to a specific offset inside a text node, I have no clue how to get this necessary offset when clicking. any ideas?
Edit: Here is the behaviour in a little screencast: https://youtu.be/RZvHxxM6wsQ
Edit2: Here is the problem reproduced on the smallest kind of working example:
https://jsfiddle.net/8z5Lnxef/3/

How to add a button in a tooltip in extjs 5

I have a simple extjs form, where all the fields look like plain text when rendered.
When user hovers over the field, i need to show a edit icon (which i am thinking would be a tooltip) next to the field (indicating that the field is editable). And when user clicks on it, the field will get focus and made editable.
Is tooltip the right component ? If not, how can i achieve this.
Thanks
A tooltip would be a bad approach - mostly because if the person mouses away from the field, the tooltip would vanish.
A simpler approach would be to include the edit icon at all times, inside the same container as the field. The edit icon should be invisible normally. Then, when the person moves the mouse into the container, make the icon visible. On mouse-exit from the container, make the icon invisible again.

Keep text input scrolling synchronized

This one's a challenge:
Suppose you have two text inputs, as in this fiddle. When the user "scrolls" inside of one (e.g. by moving the cursor to the far right or left), I'd like to "scroll" the other so that it stays in sync. Can this be done, at least in modern browsers?
I would change the text that isn't being input to an IFrame. If both need to be inputs, then dynamically switch your element from iframe to input when it is focused on/away from.
In the input box, you can find where the caret is by using the selection properties; then the IFrame can then be scrolled using scrollTo.
I'm afraid I don't have a complete solution for finding out exactly the scroll state of the input box.

Categories