From ceeefa2864ededd2f83d0a088c4862270ed850fa Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 12 Dec 2024 13:38:46 -0600 Subject: [PATCH 1/2] Close #490: remove old, problematic, and unnecessary renderError and clearError method defaults By removing these defaults, when the widget is in rendered in Shiny, it will simply fallback to Shiny's OutputBinding default methods, which does a better and simpler job of rendering and clearing errors. And, when rendering statically, the renderError/clearError methods aren't relevant --- inst/www/htmlwidgets.js | 82 ----------------------------------------- 1 file changed, 82 deletions(-) diff --git a/inst/www/htmlwidgets.js b/inst/www/htmlwidgets.js index 1067d02..cdc4363 100644 --- a/inst/www/htmlwidgets.js +++ b/inst/www/htmlwidgets.js @@ -25,14 +25,6 @@ } } - function asArray(value) { - if (value === null) - return []; - if ($.isArray(value)) - return value; - return [value]; - } - // Implement jQuery's extend function extend(target /*, ... */) { if (arguments.length == 1) { @@ -317,80 +309,6 @@ find: function(scope) { return querySelectorAll(scope, "." + this.name); }, - renderError: function(el, err) { - var $el = $(el); - - this.clearError(el); - - // Add all these error classes, as Shiny does - var errClass = "shiny-output-error"; - if (err.type !== null) { - // use the classes of the error condition as CSS class names - errClass = errClass + " " + $.map(asArray(err.type), function(type) { - return errClass + "-" + type; - }).join(" "); - } - errClass = errClass + " htmlwidgets-error"; - - // Is el inline or block? If inline or inline-block, just display:none it - // and add an inline error. - var display = $el.css("display"); - $el.data("restore-display-mode", display); - - if (display === "inline" || display === "inline-block") { - $el.hide(); - if (err.message !== "") { - var errorSpan = $("").addClass(errClass); - errorSpan.text(err.message); - $el.after(errorSpan); - } - } else if (display === "block") { - // If block, add an error just after the el, set visibility:none on the - // el, and position the error to be on top of the el. - // Mark it with a unique ID and CSS class so we can remove it later. - $el.css("visibility", "hidden"); - if (err.message !== "") { - var errorDiv = $("
").addClass(errClass).css("position", "absolute") - .css("top", el.offsetTop) - .css("left", el.offsetLeft) - // setting width can push out the page size, forcing otherwise - // unnecessary scrollbars to appear and making it impossible for - // the element to shrink; so use max-width instead - .css("maxWidth", el.offsetWidth) - .css("height", el.offsetHeight); - errorDiv.text(err.message); - $el.after(errorDiv); - - // Really dumb way to keep the size/position of the error in sync with - // the parent element as the window is resized or whatever. - var intId = setInterval(function() { - if (!errorDiv[0].parentElement) { - clearInterval(intId); - return; - } - errorDiv - .css("top", el.offsetTop) - .css("left", el.offsetLeft) - .css("maxWidth", el.offsetWidth) - .css("height", el.offsetHeight); - }, 500); - } - } - }, - clearError: function(el) { - var $el = $(el); - var display = $el.data("restore-display-mode"); - $el.data("restore-display-mode", null); - - if (display === "inline" || display === "inline-block") { - if (display) - $el.css("display", display); - $(el.nextSibling).filter(".htmlwidgets-error").remove(); - } else if (display === "block"){ - $el.css("visibility", "inherit"); - $(el.nextSibling).filter(".htmlwidgets-error").remove(); - } - }, sizing: {} }; From 57f9066b38124df669dbe75c67a03717d70da4ed Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 12 Dec 2024 13:44:38 -0600 Subject: [PATCH 2/2] Update news --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 026d9a9..421e7e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # htmlwidgets (development version) - +* Closes #490: htmlwidgets no longer inserts a new HTML element (and hides the widget HTML element) to display error messages. Instead, it now inserts error messages in the widget container. This is more consistent with how Shiny output bindings work in general, and as a result, allows the new `shiny::useBusyIndicators()` to work as intended when errors (silent or otherwise) are relevant. (#491) # htmlwidgets 1.6.4