When a button is undersized, the click event may not register

In my angular application, I have developed a directive for a tinyMCE editor. Upon setup, I have implemented two handlers: one for the blur event to hide the toolbar and another for the click event to show it. Additionally, I have created another directive containing a textarea and a button. When the button is clicked, I want the toolbar to disappear and trigger a specific action.

<body ng-app="MyApp">
<div ng-controller="MyCntrl">
        <my-directive></my-directive>
</div>
<script>
    var app = angular.module("MyApp", []);
    app.controller("MyCntrl", function ($scope) {

    }).directive("myDirective", function ( $compile) {
        return {
            restrict: 'E',
            link: function (scope, elem) {
                scope.click = function () {
                    console.log("click");
                };
            },
            template: "<textarea data-tm ></textarea><button ng-click='click()' style='width:200px; height: 74px;' id='btn'>click</button>"

        }
    }).directive("tm", function ($timeout) {
        return {
            restrict: 'A',
            link: function (scope, element) {
                $timeout(function() {
                    tinymce.init({
                        mode: 'textareas',
                        setup: function (ed) {
                            ed.on('blur', function (e) {
                                ed.theme.panel.find("toolbar").hide();
                                console.log("blur");
                            });
                            ed.on('click', function (e) {
                                ed.theme.panel.find("toolbar").show();
                            });
                        }
                    });
                });                   
            }
        }
    });
</script>

Link to the original code

When I click inside the textarea and then on the button, I noticed the following behavior: If the button's height is small, for example, 20px, only the blur event is triggered. However, when the button's height is larger, for example, 120px, both blur and click events occur simultaneously.

Can anyone explain why this is happening? My assumption is that in the first case, the button is being overlapped by something, but I am unable to identify what that might be.

Thank you

Update: I suspect there might be an issue with tinyMCE. To investigate further, I removed Angular and created a simple setup with just a tinyMCE editor and a button beneath it. The problem persists: the events only work when the button is sufficiently large or positioned above the editor.

<script type="text/javascript">
tinymce.init({
    mode: 'textareas',
    setup: function (ed) {
        ed.on('blur', function (e) {
            ed.theme.panel.find("toolbar").hide();
            console.log("blur");
        });
        ed.on('click', function (e) {
            ed.theme.panel.find("toolbar").show();
        });
    }
});

function myFunction() {
    console.log("click");
}

</script>
    <textarea></textarea>
    <button onclick="myFunction()" style="height:100px;">click</button>

Plunker link

Answer №1

One way to ensure the button stays in place during a click event is to introduce a slight timeout:

$timeout(() => { ed.theme.panel.find("toolbar").hide() }, 100);

For a demonstration, check out this example

Answer №2

By clicking the button, a toolbar disappears and the button shifts upward, ensuring that the mouse is not directly over it when released. Utilizing the mousedown event could be a possible solution to this issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using CSS to remove the background of a dropdown button in a <select> element

I need to style a <select> element so that it appears like plain text until clicked, revealing the pulldown choices. Ideally, I would like to include small arrows to indicate multiple options, but I can add those as image overlays if necessary. My p ...

It is not possible to place the cursor before a non-contenteditable div within a contenteditable div

Here is the layout I am working with: <div contenteditable=true> /// <div contenteditable=false>not editable</div> /// </div> One problem I'm facing is that when the non-contenteditable div is the first element on a ...

adjust the size of a form field to match the background image dimensions

I'm encountering an issue while trying to solve this particular challenge: My goal is to integrate a login box onto a full-screen image. Although I've come across numerous methods for incorporating an image into a form field, my task requires me ...

Bootstrap 3.2.0 Grid Column Creation Problem Identified

On my webpage using Bootstrap 3.2.0, I have a layout that includes dynamic column generation and content within those columns. However, I am facing an issue with this setup. Can anyone advise me on how to resolve it? Your help is greatly appreciated. ...

Is there a unique shape element, such as a true circle, available in HTML5?

There doesn't seem to be any documentation on this, suggesting they may not exist. However, it's always worth investigating. I am in search of a perfectly circular (or any polygon shape other than a rectangle) element. I can create a circle in c ...

Is the order of SCSS (SASS) selectors important when dealing with nested classes?

Exploring SCSS Styles for List Items In this code snippet, I am investigating the order of selection for classes and pseudo-selectors in SCSS. Specifically, I am questioning whether &:before.active is equivalent to &.active:before. Here is an exa ...

Show the WooCommerce checkout shipping fields and eliminate the "Choose a different delivery address?" checkbox

Is there a method to eliminate the checkbox labeled "Ship to a different address?" on the woocommerce checkout page while still displaying the shipping fields? I have attempted the following: add_filter( 'woocommerce_cart_needs_shipping_address', ...

Ensure that col-6 expands to fill the entire row in the event that the other col-6 is hidden on a

I'm currently working on a project that involves two columns. <div class="col-6"> <p> Here is some text for the paragraph. </p> </div> <div class="col-6 d-none d-sm-block"> <img class="goal-f1 rounded" src=" ...

Div with full height will not have scrollbars

As I work on developing a chat site, I've come across a peculiar issue with the chat display feature. Currently, my jQuery code dynamically adds chat rows to a div. My goal is to set the height of this div to 100% so that it adjusts based on the user& ...

Accessing an object from a webpage using Selenium: A step-by-step guide

Today marks my debut using Selenium IDE, and I must admit that my knowledge of web development is limited. My team is currently working on a website, and as part of my task, I need to write tests for it. The website features several charts showcasing data ...

What is the best method for locating X-Path for elements inside a frameset?

I need help creating a test case for Selenium because I am struggling to locate elements on my website. The issue seems to be related to the fact that my site uses an HTML frame set. When I try to select all links using Firebug: //a I do not get any res ...

What is causing my navbar's 'ol' element to have a wider width than the

Hello, I have a navigation bar with a dropdown menu using ol. However, when I hover over the list items, the width of the list exceeds that of the ol element. I believe this is due to the white-space: nowrap CSS property, but I want the text in the dropdow ...

Having trouble adding a custom font with override to MuiCssBaseline in react-admin, the @global @font-face seems

I am attempting to integrate the NotoSansSC-Regular.otf font from Google into my react-admin application as the default font for simplified Chinese text. I have managed to make it work by including the fonts in the root HTML file using CSS, like this: ty ...

Ensuring the sort icon is constantly displayed in MudDataGrid

Is there a way to keep the sort icon visible at all times in mudgrid without any default sorting using mudblazor? I have implemented the advanced data grid from the following link:- I have attempted using sortable=true on both the column and datagrid but ...

Is there a way to adjust the size of a table display to ensure that both vertical and horizontal scroll bars are constantly visible?

[edits added below per the request to see code. Edits also added to the original post to clarify the ask - marked in bold] My application features a broad table with the potential for many rows, generated by django-tables2 using the bootstrap5-responsive ...

CSS animation is supported on most browsers with the exception of Safari

I'm facing an issue with my animation that works fine on all browsers except Safari. I've tried using the autoprefix extension in VSCode to automatically add CSS vendor prefixes, but the animation still isn't functioning correctly. Here&apo ...

Responsive design is causing issues with the stacking of rows in Bootstrap

Currently in the process of creating a website using HTML5, CSS3, and Bootstrap technologies. Encountering difficulties while attempting to establish a stacked row-column layout. On desktop view, the design appears as desired, resembling this example: ht ...

Display additional tiles within a compact container

I'm attempting to replicate the user interface used by foursquare! Positioning the map slightly off center like they have . I've figured out how to do one part but struggling with the second part. Initially, I loaded the map in a small div (t ...

drawImage - Maintain scale while resizing

I am currently working on resizing an image using drawImage while maintaining the scale. Here is what I have so far... window.onload = function() { var c = document.getElementById("myCanvas"); var ctx = c.getContext(" ...

What is the best way to extract all image URLs from a website using JavaScript?

There are various methods to retrieve image src urls using JavaScript, such as utilizing document.images or by targeting all img elements and fetching their src attributes. However, I am currently unable to extract the image urls specified within CSS styl ...