question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to load codemirror when is hidden behind a tab

See original GitHub issue

If 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
zedeecommented, Jul 23, 2020

@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 { ... } :

import "codemirror/addon/display/autorefresh.js";

And then into your cmOptions, add this key/value:

autoRefresh: true

It worked for me, so it should for you as well!

2reactions
surmon-chinacommented, Sep 7, 2018

Try to use v-if to control component re-rendering when the container’s explicit state is switched, or manually call the component’s refresh method.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found