Skip to content

Instantly share code, notes, and snippets.

@phpmaps
Created March 17, 2021 21:11
Show Gist options
  • Select an option

  • Save phpmaps/cac4ddf48cba7fbcf48f7352dcd5edbb to your computer and use it in GitHub Desktop.

Select an option

Save phpmaps/cac4ddf48cba7fbcf48f7352dcd5edbb to your computer and use it in GitHub Desktop.
contentEditable
// https://stackoverflow.com/questions/6536166/how-to-find-absolute-or-relative-position-of-last-letter-inside-an-input-field
<div id="textbox">
<span id="edit" contentEditable></span>
<span id="end"></span>
</div>
<div id="report">x:? , y:?</div>
// css
#textbox {
border: solid black 1px;
min-height: 1em;
white-space: nowrap;
}
// javascript
$(function() {
$('#textbox').click(function() {
$('#edit').focus();
});
$('#edit').keypress(function() {
var endoff = $('#end').offset();
$('#report').html('x:' + endoff.left + ' , y:' + endoff.top);
});
});
@phpmaps
Copy link
Copy Markdown
Author

phpmaps commented Mar 17, 2021

handleKeyPress = (event) => {
  if(event.key === 'Enter'){
    console.log('enter press here! ')
  }
}
render: function(){
     return(
         <div>
           <input type="text" id="one" onKeyPress={this.handleKeyPress} />
        </div>
     );
}

@phpmaps
Copy link
Copy Markdown
Author

phpmaps commented Mar 17, 2021

    useEffect(() => {
        function listener() {
            setShowCalendar(false);
        }
        document.addEventListener("click", listener);
        return () => {
            document.removeEventListener("click", listener);
        };
    }, []);

@phpmaps
Copy link
Copy Markdown
Author

phpmaps commented Mar 17, 2021

.test {
 pointer-events: none
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment