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.

Context Menu doesn't work when container has transform: translate

See original GitHub issue

Details

  • Browser and browser version: Chrome 71.0.3578.98
  • OS version: Windows 10 & MacOS Mojave
  • xterm.js version: v3.10.1

Steps to reproduce

  1. Visit https://o9xjjwo47y.codesandbox.io/
  2. Right click anywhere inside the black xterm terminal
  3. See that it opens up the canvas context menu instead of the textarea context menu

Related: #1810

Example code snippet

Also here: https://codesandbox.io/s/o9xjjwo47y

import React from "react";
import ReactDOM from "react-dom";
import Draggable from "react-draggable";
import { Terminal } from "xterm";
import * as fit from "xterm/lib/addons/fit/fit";
import "xterm/dist/xterm.css";

import "./styles.css";

Terminal.applyAddon(fit);

class App extends React.PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      x: 0,
      y: 0
    };
  }
  componentDidMount() {
    const term = new Terminal();
    term.open(document.getElementById("xterm"));
    term.fit();
    term.write("Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ");
  }

  render() {
    const { x, y } = this.state;
    return (
      <div className="App">
        <h1>Xterm.js Right Click Bug Example</h1>
        <p>
          Right click anywhere inside the black terminal and you will see that
          the canvas context menu shows up instead of the textarea context menu
        </p>
        <p>
          If you open dev-tools and remove the "transform: translate" style from
          the parent container div, then the correct context menu shows up
        </p>
        <Draggable
          position={{ x, y }}
          onDrag={(e, data) => this.setState({ x: data.x, y: data.y })}
        >
          <div
            id="parent-container"
            style={{
              width: 500,
              height: 500,
              padding: "1em",
              background: "#333"
            }}
          >
            <div id="xterm" />
          </div>
        </Draggable>
      </div>
    );
  }
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Tyriarcommented, Jan 26, 2019

@zxlin ev.clientX and ev.clientY are probably relative to the wrong element, that would need to be tweaked to work in both cases.

0reactions
zxlincommented, Jan 27, 2019

@mofux We have xterm inside a draggable container to allow the user to lay out their work space to their personal preference. That’s simply the lib’s way of implementing draggable.

One thing of note here is that the transform style doesn’t need to be on the parent element of xterm to cause this issue, if any of xterm’s ancestor elements has the transform style, this bug occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Context Menu splits on columns - css - Stack Overflow
Here's the code, I tested it with Tampermonkey and it works fine. ... contextMenu li { border-bottom: 1px solid gray; }'); GM_addStyle('.
Read more >
translate() - CSS: Cascading Style Sheets - MDN Web Docs
This transformation is characterized by a two-dimensional vector. Its coordinates define how much the element moves in each direction. Syntax.
Read more >
Position fixed doesn't work with transform property - SitePoint
I'm the building offscreen navigation, and for pushing it I use transform: translate(x,y); . It works, all is sliding fine, but it should...
Read more >
transform - CSS-Tricks
The transform property allows you to visually manipulate an element by skewing, rotating, translating, or scaling:
Read more >
Topic: Transform, transition not working / sciter
Transform, transition not working ; E:animating, Element, at the moment, is animating e.g. expanding/collapsing, STATE_ANIMATING ; E:popup ...
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