How to load codemirror when is hidden behind a tab
See original GitHub issueIf codemirror is inside a tab, when you click the tab, by default it won’t load. Fix as follows:
<tabs>
<tab @click="refreshCodemirror">
<codemirror
ref="codeMirrorField1"
v-model="field"
:options="cmOptions" />
</tab>
<tab @click="refreshCodemirror">
<codemirror
ref="codeMirrorField2"
v-model="field2"
:options="cmOptions" />
</tab>
</tabs>
import Vue from 'vue'
export default {
methods: {
refreshCodemirror () {
Vue.nextTick(() => {
for (const $ref in this.$refs) {
if (this.$refs[$ref].hasOwnProperty('codemirror')) {
this.$refs[$ref].codemirror.refresh() // IMPORTANT CODE HERE
}
}
})
}
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Loading to Hidden textArea requires click when ...
I have a page that has 2 sections. One section contains a list of scripts, the other section containing two tabs, one tab...
Read more >How to toggle tabs to show or hide on button click in code ...
I'm having a button named toggle invisibles . If user presses the button, the spaces and the end of the line markers will...
Read more >Is there a way to show tabs and spaces in Codemirror?
Also at your disposal is the Inspect dev tool, this is Ctrl+Shft+I. Access the text in the element of the inspector and highlight...
Read more >CodeMirror Accessible - bgrins
CodeMirror uses a hidden textarea to accept input events, ... Provide a button in the menu to toggle the use of Tab between...
Read more >@uiw/react-codemirror - npm
lazyLoadMode should the mode by automatically lazy loaded. If this is set to false you will need to load the mode yourself. Defaults...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Pedrat I also had this issue and I’m using Vuetify tabs as well.
The architecture of my application makes a bit cumbersome to “communicate” to children component the active tab and trigger conditional re-render (because I have lots of tabs and sub-tabs), so this alternative solution worked for me.
From official docs: https://codemirror.net/doc/manual.html#addon_autorefresh From Stack Overflow: https://stackoverflow.com/questions/8349571/codemirror-editor-is-not-loading-content-until-clicked
You will need to add in your component file the following line before the
export default { ... }
:And then into your
cmOptions
, add this key/value:It worked for me, so it should for you as well!
Try to use
v-if
to control component re-rendering when the container’s explicit state is switched, or manually call the component’srefresh
method.