Skip to content

Fix front-end action button label updating logic #4242

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

Merged
merged 18 commits into from
Jun 26, 2025

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jun 25, 2025

Closes #4239

For context, this regression was recently introduced by the new HTML label updating feature added in #3996.

In that PR, I overlooked the fact that the updateLabel() JS helper isn't used to update labels for updateActionButton().

The logic for updating in this case is especially weird since the icon/label aren't given their own containers. So, when making the update, we need to remember the previous icon/label if either of them are NULL.

The old logic was basically assuming icon is an <i> tag. This has annoyed me in the past (for other reasons), so I opted for an approach that doesn't make assumptions about icon markup. While doing so, I also relaxed validateIcon() to stop throwing if <i> is anything other than an <i> tag.

TODO

  • Update NEWS
  • Tests

@cpsievert cpsievert requested a review from Copilot June 25, 2025 22:40
Copilot

This comment was marked as resolved.

Copy link
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, very happy to see the relaxed icon argument 👏

@cpsievert cpsievert force-pushed the fix/update-action-button-label branch from ee5621a to 8b1b374 Compare June 26, 2025 14:38
@cpsievert cpsievert requested review from gadenbuie and Copilot June 26, 2025 16:57
Copilot

This comment was marked as outdated.

Copilot

This comment was marked as outdated.

R/input-action.R Outdated
Comment on lines 97 to 99
icon_separator <- function() {
tags$span(class = "shiny-icon-separator")
}
Copy link
Member

@gadenbuie gadenbuie Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I both like this solution and have a hard time with it. It's simple and keeps the icon and text as direct children of the button.

But I don't like introducing the need for both the R and client side to maintain this markup. Would it be problematic to wrap icon and label in elements that are always present, i.e.

<a class="action-button">
  <span class="shiny-icon"><!-- icon --></span>
  <span class="shiny-label"><!-- label --></span>
</a>

Copy link
Collaborator Author

@cpsievert cpsievert Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I'm definitely opting for a less elegant implementation to minimize breaking existing CSS/JS.

It feels somewhat defendable to have a <span class="shiny-icon"> container since it seems less likely that you'd need to select the contents for that, but I'll stew on it a bit more

Copy link
Collaborator Author

@cpsievert cpsievert Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the logic has been refactored/simplified a bit, I don't hate the implementation as much. It would be simpler if containers were involved, but not so much so that it feels worth it to me (you'd still need both R and JS to be aware of the containers).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that the separator has to be included in the initial markup and is also created and removed by the JS. That feels a lot different to me than creating the markup in one place (in R) and reading it in JS. Part of why that feels okay is because we wouldn't need to remove the icon or label containers; we could use CSS to style them appropriately when they're populated or empty, so the markup would be stable throughout the lifecycle.

Anyway, that's definitely not a blocker, I think it's more important to get this fix in. Using the separator doesn't block us from using containers in the future, but using containers does present a risk of breakage if people are using .action-button > * selectors. So I'm entirely okay with merging this as-is for a release and following up with the containers approach if we'd prefer it in the long run.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, that's fair.

@cpsievert cpsievert requested a review from gadenbuie June 26, 2025 18:46
@cpsievert cpsievert merged commit f237de5 into main Jun 26, 2025
12 checks passed
@cpsievert cpsievert deleted the fix/update-action-button-label branch June 26, 2025 21:32
cpsievert added a commit that referenced this pull request Jun 27, 2025
* Follow up to #4242: Restrict icon/label separator spacing to actionButton()

* `yarn build` (GitHub Actions)

* Add spacing only when both icon and label are truthy

* Update snapshot

* `yarn build` (GitHub Actions)

* Slightly more readable JS

* `yarn build` (GitHub Actions)

---------

Co-authored-by: cpsievert <[email protected]>
cpsievert added a commit to rstudio/shinycoreci that referenced this pull request Jun 27, 2025
cpsievert added a commit to rstudio/shinycoreci that referenced this pull request Jun 27, 2025
cpsievert added a commit to rstudio/shinycoreci that referenced this pull request Jun 27, 2025
cpsievert added a commit to rstudio/shinycoreci that referenced this pull request Jun 27, 2025
cpsievert added a commit to rstudio/shinycoreci that referenced this pull request Jun 27, 2025
cpsievert added a commit to rstudio/shinycoreci that referenced this pull request Jun 27, 2025
cpsievert added a commit to rstudio/shinycoreci that referenced this pull request Jun 27, 2025
schloerke added a commit that referenced this pull request Jul 6, 2025
* main: (32 commits)
  Revert the addition of spacing between `icon` and `label` in `actionButton()` (#4248)
  Restrict `icon`/`label` separator spacing to `actionButton()` (#4247)
  Fix front-end action button label updating logic (#4242)
  Update news
  Properly handle undefined value for input subscribe callback (#4243)
  Start new version (#4241)
  v1.11.0 release candidate (#4232)
  Follow up to #3996: fix front-end checkbox label updating logic (#4238)
  feat(InputBinding): subscribe callback now supports event priority (#4211)
  Follow up to #3996 when label is unspecified (i.e., NULL), don't include it in the message (#4237)
  Run routine (#4234)
  chore: #4175 update jquery-ui to 1.14.1 (#4205)
  Update jQuery to 3.7.1 (#3969)
  Fix 404 in example 08_html (shiny.min.css) (#4221)
  Follow up to #3870: fix location of news item (#4233)
  Bugfix for error found in tests (#3870)
  Allow update input labels with HTML (#3996)
  Adds mirai to documentation (#4230)
  family->given for R Core authorship (#4222)
  fix(renderPlot): get interactive plotting working with ggplot2 v4.0 (#4228)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug related to updateActionButton after version 1.11.0
2 participants