Skip to content

Commit 2394392

Browse files
committed
Update CLAUDE.md; add checkbox single selection example
1 parent 8442b58 commit 2394392

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ New in v0.4.5.9000
1414

1515
## Development Workflow
1616

17-
1. **Update design docs**: When using Plan Mode or for major features, write planning and design docs into the `design/` directory. Use `design/virtual-scrolling/` as a model. Ensure that features consider accessibility (targeting WCAG 2.2 at a minimum) and include a test plan. Also create an Rmd file with examples of different test cases. Use mtcars dataset for examples unless another dataset is more appropriate.
17+
1. **Update design docs**: When using Plan Mode or for major features, write planning and design docs into the `design/` directory. Use `design/virtual-scrolling/` as a model. Ensure that features consider accessibility (targeting WCAG 2.2 at a minimum) and include a test plan. Also create an Rmd file with examples of different test cases. Use MASS::Cars93 or mtcars datasets for examples unless another built-in R dataset is more appropriate.
1818
2. **Make changes**
1919
3. **Document R API**: Run `devtools::document()` in R when making any changes to the R API (roxygen comments).
2020
4. **Format**: Format JavaScript code using `prettier`.

design/js-row-selection-api/js-row-selection-api-test.Rmd

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,4 +674,68 @@ tagList(
674674
elementId = "filtered-table"
675675
)
676676
)
677+
```
678+
679+
### Single selection with custom checkboxes
680+
681+
Expected: Checkboxes work with single selection mode. Clicking a row selects it and deselects any previously selected row.
682+
683+
This doesn't actually need to use the JavaScript API.
684+
685+
```{r}
686+
data <- MASS::Cars93[1:6, c("Manufacturer", "Model", "Type", "Price")]
687+
data$Select <- NA
688+
689+
reactable(
690+
data[, c("Select", "Manufacturer", "Model", "Type", "Price")],
691+
selection = "single",
692+
onClick = "select",
693+
columns = list(
694+
# Hide the default selection column
695+
.selection = colDef(show = FALSE),
696+
# Add a custom checkbox column
697+
Select = colDef(
698+
name = "",
699+
width = 45,
700+
html = TRUE,
701+
cell = JS("function(cellInfo) {
702+
const checked = cellInfo.selected ? 'checked' : ''
703+
return `<input type=\"checkbox\" ${checked} aria-label=\"Select/unselect row\">`
704+
}")
705+
)
706+
),
707+
elementId = "checkbox-single"
708+
)
709+
```
710+
711+
### Single selection with custom checkboxes (using JavaScript API)
712+
713+
Expected: Checkboxes work with single selection mode. Clicking the checkbox toggles selection using the JavaScript API.
714+
715+
```{r}
716+
data <- MASS::Cars93[1:6, c("Manufacturer", "Model", "Type", "Price")]
717+
data$Select <- NA
718+
719+
reactable(
720+
data[, c("Select", "Manufacturer", "Model", "Type", "Price")],
721+
selection = "single",
722+
columns = list(
723+
.selection = colDef(show = FALSE),
724+
Select = colDef(
725+
name = "",
726+
width = 45,
727+
cell = JS("function(cellInfo) {
728+
return React.createElement('input', {
729+
type: 'checkbox',
730+
checked: cellInfo.selected,
731+
'aria-label': 'Select/unselect row',
732+
onChange: function() {
733+
Reactable.toggleRowSelected('checkbox-single-api', cellInfo.index)
734+
}
735+
})
736+
}")
737+
)
738+
),
739+
elementId = "checkbox-single-api"
740+
)
677741
```

0 commit comments

Comments
 (0)