Skip to content

Commit

Permalink
expose closeOnClick option for scout_action
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Nov 15, 2024
1 parent fceb928 commit 0240a2c
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 5 deletions.
5 changes: 4 additions & 1 deletion R/scoutbar.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,19 @@ scout_container <- function(cl, .list, label, ...) {
#' @param id Unique id.
#' @param label Action label.
#' @param description Action description.
#' @param closeOnClick Whether to close the scoutbar whenever this action is
#' clicked. Default to TRUE.
#' @param ... Other options. See \url{https://www.scoutbar.co/docs/actions}.
#' @export
scout_action <- function(id, label, description, ...) {
scout_action <- function(id, label, description, closeOnClick = TRUE, ...) {
props <- list(
# id isn't passed to the HTML element so
# we can't find it in the DOM. This is hacky but
# works since aria-labels appears.
ariaLabel = id,
label = label,
description = description,
closeOnClick = closeOnClick,
...
)

Expand Down
5 changes: 4 additions & 1 deletion inst/www/scoutbar/scoutbar.js

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

2 changes: 1 addition & 1 deletion inst/www/scoutbar/scoutbar.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion man/scout_action.Rd

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

5 changes: 4 additions & 1 deletion srcjs/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export const processAction = (el, setValue) => {
// works since aria-labels appears.
let val = $(e.currentTarget).attr('aria-label');
setValue(val);
close(false);
// Default is true
if (children.closeOnClick) {
close(false);
}
}

func = createScoutAction(children);
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/_snaps/scoutbar/simple-001.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ariaLabel": 1,
"label": "1",
"description": "1",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -35,6 +36,7 @@
"ariaLabel": 2,
"label": "2",
"description": "2",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand Down Expand Up @@ -62,6 +64,7 @@
"ariaLabel": 3,
"label": "3",
"description": "3",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -81,6 +84,7 @@
"ariaLabel": 4,
"label": "4",
"description": "4",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -104,6 +108,7 @@
"ariaLabel": 5,
"label": "5",
"description": "5",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/_snaps/scoutbar/simple-002.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ariaLabel": 1,
"label": "1",
"description": "1",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -35,6 +36,7 @@
"ariaLabel": 2,
"label": "2",
"description": "2",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand Down Expand Up @@ -62,6 +64,7 @@
"ariaLabel": 3,
"label": "3",
"description": "3",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -81,6 +84,7 @@
"ariaLabel": 4,
"label": "4",
"description": "4",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -104,6 +108,7 @@
"ariaLabel": 5,
"label": "5",
"description": "5",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand Down
Binary file removed tests/testthat/_snaps/scoutbar/simple-002_.new.png
Binary file not shown.
Binary file modified tests/testthat/_snaps/scoutbar/simple-002_.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/testthat/_snaps/scoutbar/simple-003.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ariaLabel": 1,
"label": "1",
"description": "1",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -35,6 +36,7 @@
"ariaLabel": 2,
"label": "2",
"description": "2",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand Down Expand Up @@ -62,6 +64,7 @@
"ariaLabel": 3,
"label": "3",
"description": "3",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -81,6 +84,7 @@
"ariaLabel": 4,
"label": "4",
"description": "4",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand All @@ -104,6 +108,7 @@
"ariaLabel": 5,
"label": "5",
"description": "5",
"closeOnClick": true,
"icon": {
"type": "i",
"key": null,
Expand Down

0 comments on commit 0240a2c

Please sign in to comment.