Follow up to #3996: fix front-end checkbox label updating logic (#4238)

* Follow up to #3996: fix front-end checkbox label updating logic

* More descriptive name
This commit is contained in:
Carson Sievert
2025-06-20 15:15:30 -05:00
committed by GitHub
parent b25e6feabb
commit 673be3dd77
6 changed files with 38 additions and 27 deletions

View File

@@ -1226,12 +1226,13 @@
value: el.checked
};
}
receiveMessage(el, data) {
async receiveMessage(el, data) {
if (hasDefinedProperty(data, "value")) {
el.checked = data.value;
}
if (hasDefinedProperty(data, "label")) {
(0, import_jquery8.default)(el).parent().find("span").text(data.label);
const labelSpan = (0, import_jquery8.default)(el).parent().find("span");
await renderContent(labelSpan, data.label);
}
(0, import_jquery8.default)(el).trigger("change");
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +1,16 @@
import $ from "jquery";
import type { HtmlDep } from "../../shiny/render";
import { renderContent } from "../../shiny/render";
import { hasDefinedProperty } from "../../utils";
import { InputBinding } from "./inputBinding";
type CheckedHTMLElement = HTMLInputElement;
type CheckboxChecked = CheckedHTMLElement["checked"];
type CheckboxReceiveMessageData = { value?: CheckboxChecked; label?: string };
type CheckboxReceiveMessageData = {
value?: CheckboxChecked;
label?: { html: string; deps: HtmlDep[] };
};
class CheckboxInputBinding extends InputBinding {
find(scope: HTMLElement): JQuery<HTMLElement> {
@@ -32,10 +37,10 @@ class CheckboxInputBinding extends InputBinding {
value: el.checked,
};
}
receiveMessage(
async receiveMessage(
el: CheckedHTMLElement,
data: CheckboxReceiveMessageData
): void {
): Promise<void> {
if (hasDefinedProperty(data, "value")) {
el.checked = data.value;
}
@@ -43,7 +48,8 @@ class CheckboxInputBinding extends InputBinding {
// checkboxInput()'s label works different from other
// input labels...the label container should always exist
if (hasDefinedProperty(data, "label")) {
$(el).parent().find("span").text(data.label);
const labelSpan = $(el).parent().find("span");
await renderContent(labelSpan, data.label);
}
$(el).trigger("change");

View File

@@ -1,9 +1,13 @@
import type { HtmlDep } from "../../shiny/render";
import { InputBinding } from "./inputBinding";
type CheckedHTMLElement = HTMLInputElement;
type CheckboxChecked = CheckedHTMLElement["checked"];
type CheckboxReceiveMessageData = {
value?: CheckboxChecked;
label?: string;
label?: {
html: string;
deps: HtmlDep[];
};
};
declare class CheckboxInputBinding extends InputBinding {
find(scope: HTMLElement): JQuery<HTMLElement>;
@@ -15,7 +19,7 @@ declare class CheckboxInputBinding extends InputBinding {
label: string;
value: CheckboxChecked;
};
receiveMessage(el: CheckedHTMLElement, data: CheckboxReceiveMessageData): void;
receiveMessage(el: CheckedHTMLElement, data: CheckboxReceiveMessageData): Promise<void>;
}
export { CheckboxInputBinding };
export type { CheckedHTMLElement, CheckboxReceiveMessageData };