From cd6a00051dec6fc8ee016f65cef9834da9230d35 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Fri, 13 Feb 2026 11:26:14 +0000 Subject: [PATCH] Added htmlAppendAttributes method and fixed accessibility with help link icons (title -> aria-label) --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/htmlAppendAttributes.R | 14 ++++++++++++++ R/htmlBoxManipulation.R | 3 ++- man/htmlAppendAttributes.Rd | 23 +++++++++++++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 R/htmlAppendAttributes.R create mode 100644 man/htmlAppendAttributes.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 2519d3d..6ff9c3d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AVSDevR.HTMLUtils Title: Utility Functions For Modifying R HTML Elements -Version: 0.1.0 +Version: 0.1.0.9000 Authors@R: person("Craig", "Williams", , "craig@avsdev.uk", role = c("aut", "cre")) Description: Collection of utility functions for modifying HTML markup of diff --git a/NAMESPACE b/NAMESPACE index 623cc18..49e99cd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(htmlAddBoxAttributes) export(htmlAddBoxHelpLink) export(htmlAddBoxRegionFromTitle) export(htmlAddClasses) +export(htmlAppendAttributes) export(htmlButtonStyle) export(htmlDisableAutocomplete) export(htmlFixBoxCollapseButtonAria) diff --git a/R/htmlAppendAttributes.R b/R/htmlAppendAttributes.R new file mode 100644 index 0000000..a3496aa --- /dev/null +++ b/R/htmlAppendAttributes.R @@ -0,0 +1,14 @@ +#' Appends attributes to an HTML element +#' +#' @param el The element to append the attributes to +#' @param ... The attribute names to be appended +#' +#' @return The modified element +#' @export +#' +#' @examples +#' x <- shiny::icon("wrench") +#' htmlAppendAttributes(x, `role` = "presentation") +htmlAppendAttributes <- function(el, ...) { + do.call(htmltools::tagQuery(el)$addAttrs, list(...))$allTags() +} diff --git a/R/htmlBoxManipulation.R b/R/htmlBoxManipulation.R index 80aec03..18d6f17 100644 --- a/R/htmlBoxManipulation.R +++ b/R/htmlBoxManipulation.R @@ -135,7 +135,8 @@ htmlAddBoxHelpLink <- function(box, href, title = NULL) { target = "_blank", class = "btn btn-box-tool pl-3 pr-3", htmlRemoveAttributes(shiny::icon("question"), "aria-label"), - title = paste(trimws(title), " help link") + title = paste(trimws(title), " help link"), + `aria-label` = paste(trimws(title), " help link") ) ) } diff --git a/man/htmlAppendAttributes.Rd b/man/htmlAppendAttributes.Rd new file mode 100644 index 0000000..9f6e3f1 --- /dev/null +++ b/man/htmlAppendAttributes.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/htmlAppendAttributes.R +\name{htmlAppendAttributes} +\alias{htmlAppendAttributes} +\title{Appends attributes to an HTML element} +\usage{ +htmlAppendAttributes(el, ...) +} +\arguments{ +\item{el}{The element to append the attributes to} + +\item{...}{The attribute names to be appended} +} +\value{ +The modified element +} +\description{ +Appends attributes to an HTML element +} +\examples{ +x <- shiny::icon("wrench") +htmlAppendAttributes(x, `role` = "presentation") +}