Skip to content

Commit

Permalink
add startExpanded arg
Browse files Browse the repository at this point in the history
  • Loading branch information
hypebright committed Mar 18, 2024
1 parent 667fe95 commit 325c25f
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
6 changes: 4 additions & 2 deletions R/f7Treeview.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
#' @param id Treeview unique id.
#' @param selectable Make treeview items selectable. Default is `FALSE`.
#' @param withCheckbox Add a checkbox to each item. Default is `FALSE`.
#' @param startExpanded Whether to expand the treeview at start.
#'
#' @example inst/examples/treeview/app.R
#'
#' @export

f7Treeview <- function(..., id, selectable = FALSE, withCheckbox = FALSE) {
f7Treeview <- function(..., id, selectable = FALSE, withCheckbox = FALSE, startExpanded = FALSE) {

config <- dropNulls(
list(
selectable = selectable,
withCheckbox = withCheckbox
withCheckbox = withCheckbox,
startExpanded = startExpanded
)
)

Expand Down
1 change: 1 addition & 0 deletions inst/examples/treeview/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ app <- shinyApp(
f7Block(
f7Treeview(
id = "group",
startExpanded = TRUE,
f7TreeviewGroup(
title = "Images",
icon = f7Icon("folder_fill"),
Expand Down
2 changes: 1 addition & 1 deletion inst/shinyMobile-1.0.1/dist/shinyMobile.min.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/shinyMobile-1.0.1/dist/shinyMobile.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inst/shinyMobile-1.0.1/dist/shinyMobile.min.js.map

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions man/f7Treeview.Rd

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

7 changes: 5 additions & 2 deletions man/f7TreeviewItem.Rd

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

14 changes: 14 additions & 0 deletions srcjs/bindings/treeviewInputBinding.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { getAppInstance } from "../init.js";

var f7TreeviewBinding = new Shiny.InputBinding();

$.extend(f7TreeviewBinding, {

initialize: function(el) {

this.app = getAppInstance();

var id = $(el).attr("id");
var config = $(el).find("script[data-for='" + id + "']");

Expand Down Expand Up @@ -58,6 +63,15 @@ $.extend(f7TreeviewBinding, {
});
}

// lexical scoping
var self = this;
if (this.config[id].startExpanded) {
// open all treeview-item elements
$(el).find(".treeview-item").each(function() {
self.app.treeview.open(this);
});
}

},

find: function(scope) {
Expand Down

0 comments on commit 325c25f

Please sign in to comment.