vexflow icon indicating copy to clipboard operation
vexflow copied to clipboard

Passing DOM element to Factory's renderer.elementId param

Open devboell opened this issue 7 years ago • 3 comments

I am wondering about the EasyScore example, and how you configure the renderer by means of the Factory.

Because I am using React I don't want to use getElementById, but get the DOM element with React Component's ref attribute

Although the Factory explicitly asks for a elementId, I see in Renderer that it is still ok to pass the element itself.

    this.element = document.getElementById(elementId);
    if (!this.element) this.element = elementId;

Can I safely assume this option will remain available in the future?

devboell avatar Oct 07 '17 17:10 devboell

wouldn't it be best to add a new option "element" to make it more explicit (while keeping the possibility to give element as elementId ?, so that you don't break backward compatibility )

allan-simon avatar Jul 15 '18 23:07 allan-simon

I also would like to use (rely on) this option so would appreciate a formal acknowledgment in the API. Even the ability to pass a Renderer directly (instead of renderer configuration) would be great. Either of these would be great:

// Factory 'renderer' config accepts an 'element' property as a DOM element
const vf = new Vex.Flow.Factory({renderer: { element: vexElementRef.current }});
// Factory 'renderer' option accepts a vex renderer instance
const renderer = new Renderer(vexElementRef.current, Renderer.Backends.SVG);
const vf = new Vex.Flow.Factory({renderer});

alindsay55661 avatar Sep 25 '22 16:09 alindsay55661

Looking into that we do have a inconsistency between the parameter used by:

  • Factory which is defined as string | null , and
  • Renderer which is defined as string | HTMLCanvasElement | HTMLDivElement | RenderContext

It would make sense to accept the same possibilities in Factory, wouldn't it?

rvilarl avatar Sep 25 '22 18:09 rvilarl