Skip to content

Commit

Permalink
feat(card_image): Add alt parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Jun 12, 2024
1 parent e32a918 commit 3656364
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
10 changes: 10 additions & 0 deletions R/card.R
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ card_footer <- function(..., class = NULL) {
#' starting with `https://` or similar) will be base64 encoded and provided to
#' the `src` attribute of the `<img>`. Alternatively, you may directly set
#' the image `src`, in which case `file` is ignored.
#' @param alt Alternate text for the image, used by screen readers and assistive
#' devices. Provide alt text with a description of the image for any images
#' with important content. If alt text is not provided, the image will be
#' considered to be decorative and will not be read or announced by screen
#' readers.
#'
#' For more information, the Web Accessibility Initiative (WAI) has a
#' [helpful tutorial on alt text](https://www.w3.org/WAI/tutorials/images/).
#' @param href An optional URL to link to when a user clicks on the image.
#' @param border_radius Which side of the image should have rounded corners,
#' useful when `card_image()` is used as an image cap at the top or bottom of
Expand All @@ -279,6 +287,7 @@ card_footer <- function(..., class = NULL) {
#' @export
card_image <- function(
file,
alt = "",
...,
src = NULL,
href = NULL,
Expand All @@ -305,6 +314,7 @@ card_image <- function(

image <- tags$img(
src = src,
alt = alt,
class = "img-fluid",
class = switch(
border_radius,
Expand Down
10 changes: 10 additions & 0 deletions man/card_body.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/card.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"image cap on top of card")))
Output
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
<img class="img-fluid card-img-top" src="https://example.com/image.jpg"/>
<img alt="" class="img-fluid card-img-top" src="https://example.com/image.jpg"/>
<div class="card-body bslib-gap-spacing html-fill-item html-fill-container" style="margin-top:auto;margin-bottom:auto;flex:1 1 auto;">image cap on top of card</div>
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>
</div>
Expand All @@ -18,7 +18,7 @@
Output
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
<div class="card-body bslib-gap-spacing html-fill-item html-fill-container" style="margin-top:auto;margin-bottom:auto;flex:1 1 auto;">image cap on bottom of card</div>
<img class="img-fluid card-img-bottom" src="https://example.com/image.jpg"/>
<img alt="" class="img-fluid card-img-bottom" src="https://example.com/image.jpg"/>
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>
</div>

Expand All @@ -30,7 +30,7 @@
Output
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
<div class="card-header">header</div>
<img src="https://example.com/image.jpg" class="img-fluid"/>
<img src="https://example.com/image.jpg" alt="" class="img-fluid"/>
<div class="card-body bslib-gap-spacing html-fill-item html-fill-container" style="margin-top:auto;margin-bottom:auto;flex:1 1 auto;">image not a cap</div>
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>
</div>
Expand Down

0 comments on commit 3656364

Please sign in to comment.