Added htmlAppendAttributes method and fixed accessibility with help link icons (title -> aria-label)

This commit is contained in:
2026-02-13 11:26:14 +00:00
parent 9edf74fc11
commit cd6a00051d
5 changed files with 41 additions and 2 deletions

View File

@@ -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

View File

@@ -4,6 +4,7 @@ export(htmlAddBoxAttributes)
export(htmlAddBoxHelpLink)
export(htmlAddBoxRegionFromTitle)
export(htmlAddClasses)
export(htmlAppendAttributes)
export(htmlButtonStyle)
export(htmlDisableAutocomplete)
export(htmlFixBoxCollapseButtonAria)

14
R/htmlAppendAttributes.R Normal file
View File

@@ -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()
}

View File

@@ -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")
)
)
}

View File

@@ -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")
}