fix(admin-ui): pass contextual names to native Monaco editor

This commit is contained in:
Joseph Doherty
2026-11-13 21:04:30 -05:00
parent 2415db8ca4
commit 8cc053ceb7
13 changed files with 499 additions and 0 deletions
@@ -39,6 +39,8 @@
[Parameter] public string Value { get; set; } = "";
/// <summary>Raised with the editor text when the editor loses focus after an edit (and from <see cref="GetValueAsync"/>).</summary>
[Parameter] public EventCallback<string> ValueChanged { get; set; }
/// <summary>The domain-specific accessible name passed to Monaco's internal text editor.</summary>
[Parameter] public string AriaLabel { get; set; } = "Code editor";
[Parameter] public string Language { get; set; } = "csharp";
[Parameter] public string Height { get; set; } = "320px";
[Parameter] public bool ReadOnly { get; set; } = false;
@@ -64,6 +66,9 @@
private DotNetObjectReference<MonacoEditor>? _dotNetRef;
private readonly string _id = Guid.NewGuid().ToString("N");
private string _lastSentValue = "";
private string _lastSentAriaLabel = "";
private string AccessibleLabel => string.IsNullOrWhiteSpace(AriaLabel) ? "Code editor" : AriaLabel;
private bool _disposed;
private bool _initialized;
private int _tooLargeBytes;
private bool _wrap;
@@ -76,6 +81,7 @@
{
_dotNetRef = DotNetObjectReference.Create(this);
_lastSentValue = Value ?? "";
var createdLabel = AccessibleLabel;
try
{
await JS.InvokeVoidAsync(
@@ -85,6 +91,7 @@
new
{
value = Value ?? "",
ariaLabel = createdLabel,
language = Language,
readOnly = ReadOnly,
equipmentId = EquipmentId,
@@ -95,6 +102,7 @@
},
_dotNetRef);
_initialized = true;
_lastSentAriaLabel = createdLabel;
}
catch (InvalidOperationException)
{
@@ -116,6 +124,11 @@
_lastSentValue = Value ?? "";
await SafeInvokeAsync("MonacoBlazor.setValue", "set editor value", _id, _lastSentValue);
}
if (!_disposed && _initialized && AccessibleLabel != _lastSentAriaLabel)
{
_lastSentAriaLabel = AccessibleLabel;
await SafeInvokeAsync("MonacoBlazor.setEditorOption", "set accessible editor name", _id, "ariaLabel", _lastSentAriaLabel);
}
}
/// <summary>
@@ -237,6 +250,7 @@
public async ValueTask DisposeAsync()
{
_disposed = true;
try
{
if (_initialized)
@@ -231,6 +231,7 @@
if (!host) return;
const editor = monaco.editor.create(host, {
value: options.value || "", language: options.language || "csharp",
ariaLabel: typeof options.ariaLabel === "string" && options.ariaLabel.trim() ? options.ariaLabel : "Code editor",
theme: "vs", minimap: { enabled: false }, scrollBeyondLastLine: false,
automaticLayout: true, fontSize: 13, lineNumbers: "on",
renderLineHighlight: "line", readOnly: !!options.readOnly,