-
-
Notifications
You must be signed in to change notification settings - Fork 603
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
react-ace in resizable container #207
Comments
@MartinHaeusler thanks for the issue. I'm working on this right now. should be out in |
@MartinHaeusler this is out now in |
Thanks for this very fast response! I just upgraded my package.json to use |
@MartinHaeusler could you probably share a link to solution you created? |
@dmigo: I tried using react-measure for the job. However, it only worked in some cases, not all of them. There were always some odd corner cases left where the editor wouldn't behave as intended. In the end, I switched from Ace to CodeMirror for that reason. I had some issues there as well with making things resizable and had to do some quite ugly hacks, but that works now. Sorry, I discarded the prototype for the resizable react-ace editor shortly after. But it never really worked properly as intended anyways. |
@securingsincity |
@dmigo that sounds great! If we think that could solve the issues let's do it |
@dmigo Nice catch! That might have been the issue for me as well. |
I'm up to it! |
I upgraded to 5.1.2 and calling AceEditor with the props:
Is there anything I need to add to get it to resize to the container? |
Anyone figure out how to automatically resize the container based on user-control? I'm trying to:
|
I succeed by using react-resize-detector import AceEditor from 'react-ace'
import ReactResizeDetector from 'react-resize-detector'
export default class myComponent extends Component {
constructor (props) {
super(props)
this.state = {
editorHeight: 400,
editorWidth: "auto"
}
this.onResize = this.onResize.bind(this)
}
onResize (w, h) {
this.setState({
editorHeight: h,
editorWidth: w
})
}
render () {
<div className="resizable">
<ReactResizeDetector handleWidth handleHeight onResize={this.onResize} />
<AceEditor
height={this.state.editorHeight}
width={this.state.editorWidth}
/>
</div>
}
} CSS of .resizable {
overflow: auto;
resize: both;
height: 400px;
width: auto;
} |
here is a pure css solution, using CSS <AceEditor
onLoad={editorInstance => {
editorInstance.container.style.resize = "both";
// mouseup = css resize end
document.addEventListener("mouseup", e => (
editorInstance.resize()
));
}}
/> downside: on resize-larger the editor content is hidden here is a demo fiddle with vanilla js |
Thanks @milahu your solution worked perfectly for my use case. |
Thanks @milahu vary much.Your solution so helpful. In addition, It will be better to use the event "window.onresize". |
Thanks, @milahu your solution works fine. Unfortunately, this approach is not working in safari :( Do someone faced with the same problem? Looks like it's safari specific problem with resizing. You can check it out with the above example |
add a className to AceEditor component and use this in your CSS or other styling file .ace-editor { |
I am trying to use
react-ace
inside adiv
that can be resized by the user at runtime (to be precise, the size of thediv
is controlled by aflexbox
). By default, the ACE editor requires fixed with and height values in pixels.By using react-measure and some
div
nesting, I was able to get the ACE Editor to resize its bounds correctly, at least visually. However, the controls inside the editor (e.g. the width of the line wrapping, the scroll bar, ...) behave weirdly, because they did not get properly notified about the change in editor dimensions.The "vanilla" ACE editor has a
resize()
method to fix just that problem (see this fiddle).My request is: please either forward
resize()
inreact-ace
, or callresize()
internally oncomponentWillReceiveProps
in case thatwidth
and/orheight
has changed.EDIT: I had a quick look at the source code. You actually do this:
... but what about changes in width? Shouldn't it be this:
The text was updated successfully, but these errors were encountered: