marcio / react-skylight

A react component for modals and dialogs
http://marcio.github.io/react-skylight/
MIT License
571 stars 97 forks source link

How to get access to element inside Modal? #27

Closed purezen closed 8 years ago

purezen commented 8 years ago

Hi, I have been trying to implement autofocus on a text input field inside a modal. I started by calling focus() on the element inside the _executeAfterModalOpen() callback. An alert function inside the callback is working fine. But it looks like this inside the callback is not pointing to the component. So, this.refs is showing up as _unassigned_ which I am trying to use to get hold of the input field in turn doing this.refs.modal.focus().

EDIT: I meant this.refs is showing up as undefined.

marcio commented 8 years ago

Hi, maybe this example help you.


_executeAfterModalOpen(){
    this.refs.myInput.focus();
}

<SkyLight afterOpen={this._executeAfterModalOpen}><input ref='myInput' type='text' /></SkyLight>

Please, let me know if that works :+1:

purezen commented 8 years ago

Well, that's what I have been trying. But still doesn't work.

purezen commented 8 years ago

Hey, can you confirm if that is working? Coz, for me this inside _executeAfterModelOpen() is pointing to something else.

Object { 
  hideOnOverlayClicked: true, 
  afterOpen: wrapMethod/<(),
  dialogStyles: Object,
  title: "Improve task", 
  children: Object,
  showOverlay: true,
  overlayStyles: Object,
  closeButtonStyle: Object
}