Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

27.on blur event #28

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# reactable.extras (development version)

* `text_extra` now allows to listen to the `onBlur` event
# reactable.extras 0.1.0.9000

## Server-Side Processing
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ shinyApp(
textOutput("button_text"),
textOutput("check_text"),
textOutput("dropdown_text"),
textOutput("text")
textOutput("text_text"),
textOutput("text_on_blur")
),
server = function(input, output) {
output$react <- renderReactable({
Expand Down Expand Up @@ -209,11 +210,20 @@ shinyApp(
)
})

output$text <- renderText({
output$text_text <- renderText({
req(input$text)
values <- input$text
paste0(
"Dropdown: ",
"Text: ",
string_list(values)
)
})

output$text_on_blur <- renderText({
req(input$text_blur)
values <- input$text_blur
paste0(
"Text on blur: ",
string_list(values)
)
})
Expand Down
2 changes: 2 additions & 0 deletions e2e_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
cypress/screenshots/
cypress/videos/
12 changes: 12 additions & 0 deletions e2e_tests/cypress/e2e/spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ describe('Date in reactable passes values to the shiny', () => {
});
})

// test for checking text input inside the reactable
describe('Text Extra passes values to the Shiny App', () => {
it('TextExtra', () => {
cy.visit('http://localhost:8888');
cy.get('.text-extra').eq(1).clear().type('new_value').should('have.value', 'new_value');
cy.contains('Text: {row : id_2, value : new_value, column : Model}');
// Click on body to trigger onBlur event
cy.get('body').click();
cy.contains('Text OnBlur: {row : id_2, value : new_value, column : Model}');
});
})

2 changes: 1 addition & 1 deletion e2e_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"description": "For running cypress tests",
"scripts": {
"start-test-app": "cd ../inst/examples/demo/reactable-inputs && Rscript -e 'shiny::runApp(port=8888)'",
"start-test-app": "cd ../inst/examples/demo/reactable-inputs && Rscript -e 'devtools::load_all(); shiny::runApp(port=8888)'",
"e2e-test": "start-server-and-test start-test-app http://localhost:8888 'cypress run --record false'"
},
"main": "index.js",
Expand Down
6 changes: 5 additions & 1 deletion inst/assets/js/reactable-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ function textExtras ({ id, value, uuid, column, page, className, children }) {
Shiny.setInputValue(id, { row: uuid, value: event.target.value, column: column }, { priority: 'event' })
}

const onBlur = event => {
Shiny.setInputValue(`${id}_blur`, { row: uuid, value: event.target.value, column: column }, { priority: 'event' })
}

return React.createElement(
'input',
{ onInput, className, defaultValue: value, key: uuid }
{ onInput, onBlur, className, defaultValue: value, key: uuid }
)
};

25 changes: 23 additions & 2 deletions inst/examples/demo/reactable-inputs/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ shinyApp(
textOutput("button_text"),
textOutput("check_text"),
textOutput("dropdown_text"),
textOutput("text")
textOutput("text"),
textOutput("text_on_blur")
),
server = function(input, output) {
df <- MASS::Cars93[, 1:4] |>
Expand Down Expand Up @@ -73,7 +74,8 @@ shinyApp(
Model = colDef(
cell = text_extra(
"text",
key = "id_row"
key = "id_row",
class = "text-extra"
)
)
)
Expand Down Expand Up @@ -142,5 +144,24 @@ shinyApp(
string_list(values)
)
})

output$text_on_blur <- renderText({
req(input$text_blur)
values <- input$text_blur
updateReactable(
"react",
data = update_table(
df,
values$row,
values$column,
values$value,
key_column = "id_row"
)
)
paste0(
"Text OnBlur: ",
string_list(values)
)
})
}
)