Skip to content
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

Big issue when creating a custom context menu #57

Open
AlenToma opened this issue Mar 23, 2022 · 0 comments
Open

Big issue when creating a custom context menu #57

AlenToma opened this issue Mar 23, 2022 · 0 comments

Comments

@AlenToma
Copy link

Hi, I am using this library to display some button so I could for example copy, share etc.

The problem is that the Popover disappear before the click event even trigger. there should be a settimeout at least so that click event may trigger if the popup previous state is visible.

Please could you check this out. I saw that you are using use-text-selection are you the owner of the library ?

should this problem be handled here or in use-text-selection.

Here is a code view should if you are interested of what I mean.

         {
            this.props.bookOption.selectionMenus && this.props.bookOption.selectionMenus.length ? (
              <Popover
                mount={this.chapterRef.current as HTMLElement | undefined}
                render={
                  ({ clientRect, isCollapsed, textContent }) => {

                    if (clientRect == null || isCollapsed) return null
                    var row = "";
                    var column = "";
                    if (this.props.bookOption.selectionMenus) {
                      this.props.bookOption.selectionMenus.forEach((_, i) => {
                        if (i % 3 === 0)
                          row += " 1fr";
                      });

                      if (this.props.bookOption.selectionMenus.length >= 3)
                        column = "1fr 1fr 1fr";
                      else column = this.props.bookOption.selectionMenus.map(() => "1fr").join(" ");

                    }

                    // I'm using emotion for this example but you can use anything really
                    const style = {
                      position: "absolute",
                      left: document.documentElement.scrollLeft + (clientRect.left + clientRect.width / 2),
                      top: document.documentElement.scrollTop + (clientRect.top - 40),
                      marginLeft: -75,
                      gridTemplateColumns: column,
                      gridTemplateRows: row
                    } as React.CSSProperties

                    return <div className='bookMenu' style={style}>
                      {
                        this.props.bookOption.selectionMenus?.map((x, i) => (
                          <a key={i} onClick={(event) => {
                           // this never trigger.
                            var result = {
                              selectedText: textContent,
                              rec: clientRect,
                              menuIndex: i
                            } as SelectionResult
                            console.log(result)
                            if (this.props.bookOption.selectionMenuClick)
                              this.props.bookOption.selectionMenuClick(result);
                          }}>
                            {
                              x.icon && typeof x.icon === "string" ? (<img src={x.icon} />) : null
                            }
                            {
                              x.icon && typeof x.icon !== "string" ? (x.icon) : null
                            }
                            {x.text}
                          </a>
                        ))
                      }
                    </div>
                  }
                }
              />
            ) : null}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant