-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Allow update input labels with HTML #3996
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
Changes from 3 commits
ae7c316
2c566e3
dfac222
62283b3
0229ee5
49032c9
8926716
ca26f39
86cfa72
962e0f2
4f4c05a
03c7847
f98c06c
f980d4a
6b97b63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import $ from "jquery"; | ||
| import { windowDevicePixelRatio } from "../window/pixelRatio"; | ||
| import type { MapValuesUnion, MapWithResult } from "./extraTypes"; | ||
| import type { HtmlDep } from "../shiny/render"; | ||
| import { hasOwnProperty, hasDefinedProperty } from "./object"; | ||
| import { renderContent } from "../shiny/render"; | ||
|
|
||
| function escapeHTML(str: string): string { | ||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
|
|
@@ -336,23 +338,31 @@ const compareVersion = function ( | |
| else throw `Unknown operator: ${op}`; | ||
| }; | ||
|
|
||
| function updateLabel( | ||
| labelTxt: string | undefined, | ||
| async function updateLabel( | ||
| labelContent: string | { html: string; deps: HtmlDep[] } | undefined, | ||
| labelNode: JQuery<HTMLElement> | ||
| ): void { | ||
| ): Promise<void> { | ||
| // Only update if label was specified in the update method | ||
| if (typeof labelTxt === "undefined") return; | ||
| if (typeof labelContent === "undefined") return; | ||
| if (labelNode.length !== 1) { | ||
| throw new Error("labelNode must be of length 1"); | ||
| } | ||
|
|
||
| if (typeof labelContent === "string") { | ||
| labelContent = { | ||
| html: labelContent, | ||
| deps: [], | ||
| }; | ||
| } | ||
|
|
||
| // Should the label be empty? | ||
| const emptyLabel = Array.isArray(labelTxt) && labelTxt.length === 0; | ||
| const emptyLabel = | ||
| Array.isArray(labelContent.html) && labelContent.html.length === 0; | ||
|
||
|
|
||
| if (emptyLabel) { | ||
| labelNode.addClass("shiny-label-null"); | ||
| } else { | ||
| labelNode.text(labelTxt); | ||
| await renderContent(labelNode, labelContent); | ||
| labelNode.removeClass("shiny-label-null"); | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.