mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-09 23:18:10 -05:00
* Follow up to #3996: fix front-end checkbox label updating logic * More descriptive name
This commit is contained in:
@@ -1226,12 +1226,13 @@
|
|||||||
value: el.checked
|
value: el.checked
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
receiveMessage(el, data) {
|
async receiveMessage(el, data) {
|
||||||
if (hasDefinedProperty(data, "value")) {
|
if (hasDefinedProperty(data, "value")) {
|
||||||
el.checked = data.value;
|
el.checked = data.value;
|
||||||
}
|
}
|
||||||
if (hasDefinedProperty(data, "label")) {
|
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");
|
(0, import_jquery8.default)(el).trigger("change");
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
28
inst/www/shared/shiny.min.js
vendored
28
inst/www/shared/shiny.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,11 +1,16 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
|
import type { HtmlDep } from "../../shiny/render";
|
||||||
|
import { renderContent } from "../../shiny/render";
|
||||||
import { hasDefinedProperty } from "../../utils";
|
import { hasDefinedProperty } from "../../utils";
|
||||||
import { InputBinding } from "./inputBinding";
|
import { InputBinding } from "./inputBinding";
|
||||||
|
|
||||||
type CheckedHTMLElement = HTMLInputElement;
|
type CheckedHTMLElement = HTMLInputElement;
|
||||||
|
|
||||||
type CheckboxChecked = CheckedHTMLElement["checked"];
|
type CheckboxChecked = CheckedHTMLElement["checked"];
|
||||||
type CheckboxReceiveMessageData = { value?: CheckboxChecked; label?: string };
|
type CheckboxReceiveMessageData = {
|
||||||
|
value?: CheckboxChecked;
|
||||||
|
label?: { html: string; deps: HtmlDep[] };
|
||||||
|
};
|
||||||
|
|
||||||
class CheckboxInputBinding extends InputBinding {
|
class CheckboxInputBinding extends InputBinding {
|
||||||
find(scope: HTMLElement): JQuery<HTMLElement> {
|
find(scope: HTMLElement): JQuery<HTMLElement> {
|
||||||
@@ -32,10 +37,10 @@ class CheckboxInputBinding extends InputBinding {
|
|||||||
value: el.checked,
|
value: el.checked,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
receiveMessage(
|
async receiveMessage(
|
||||||
el: CheckedHTMLElement,
|
el: CheckedHTMLElement,
|
||||||
data: CheckboxReceiveMessageData
|
data: CheckboxReceiveMessageData
|
||||||
): void {
|
): Promise<void> {
|
||||||
if (hasDefinedProperty(data, "value")) {
|
if (hasDefinedProperty(data, "value")) {
|
||||||
el.checked = data.value;
|
el.checked = data.value;
|
||||||
}
|
}
|
||||||
@@ -43,7 +48,8 @@ class CheckboxInputBinding extends InputBinding {
|
|||||||
// checkboxInput()'s label works different from other
|
// checkboxInput()'s label works different from other
|
||||||
// input labels...the label container should always exist
|
// input labels...the label container should always exist
|
||||||
if (hasDefinedProperty(data, "label")) {
|
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");
|
$(el).trigger("change");
|
||||||
|
|||||||
8
srcts/types/src/bindings/input/checkbox.d.ts
vendored
8
srcts/types/src/bindings/input/checkbox.d.ts
vendored
@@ -1,9 +1,13 @@
|
|||||||
|
import type { HtmlDep } from "../../shiny/render";
|
||||||
import { InputBinding } from "./inputBinding";
|
import { InputBinding } from "./inputBinding";
|
||||||
type CheckedHTMLElement = HTMLInputElement;
|
type CheckedHTMLElement = HTMLInputElement;
|
||||||
type CheckboxChecked = CheckedHTMLElement["checked"];
|
type CheckboxChecked = CheckedHTMLElement["checked"];
|
||||||
type CheckboxReceiveMessageData = {
|
type CheckboxReceiveMessageData = {
|
||||||
value?: CheckboxChecked;
|
value?: CheckboxChecked;
|
||||||
label?: string;
|
label?: {
|
||||||
|
html: string;
|
||||||
|
deps: HtmlDep[];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
declare class CheckboxInputBinding extends InputBinding {
|
declare class CheckboxInputBinding extends InputBinding {
|
||||||
find(scope: HTMLElement): JQuery<HTMLElement>;
|
find(scope: HTMLElement): JQuery<HTMLElement>;
|
||||||
@@ -15,7 +19,7 @@ declare class CheckboxInputBinding extends InputBinding {
|
|||||||
label: string;
|
label: string;
|
||||||
value: CheckboxChecked;
|
value: CheckboxChecked;
|
||||||
};
|
};
|
||||||
receiveMessage(el: CheckedHTMLElement, data: CheckboxReceiveMessageData): void;
|
receiveMessage(el: CheckedHTMLElement, data: CheckboxReceiveMessageData): Promise<void>;
|
||||||
}
|
}
|
||||||
export { CheckboxInputBinding };
|
export { CheckboxInputBinding };
|
||||||
export type { CheckedHTMLElement, CheckboxReceiveMessageData };
|
export type { CheckedHTMLElement, CheckboxReceiveMessageData };
|
||||||
|
|||||||
Reference in New Issue
Block a user