Skip to content

Commit

Permalink
Fix #1215: make datalist work
Browse files Browse the repository at this point in the history
Fix #1226: Add Element to AutoComplete TextField
  • Loading branch information
vnbaaij committed Dec 28, 2023
1 parent 5d585ae commit 4b775a0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,9 @@
<param name="component">The type of the component to show</param>
<param name="parameters"><see cref="T:Microsoft.FluentUI.AspNetCore.Components.SplashScreenContent"/> that holds the content to display</param>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.#ctor">
<summary />
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.DialogService.CreateDialogCallback(System.Object,System.Func{Microsoft.FluentUI.AspNetCore.Components.DialogResult,System.Threading.Tasks.Task})">
<summary>
Convenience method to create a <see cref="T:Microsoft.AspNetCore.Components.EventCallback"/> for a dialog result.
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Components/Base/FluentInputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public override Task SetParametersAsync(ParameterView parameters)
return base.SetParametersAsync(ParameterView.Empty);
}

// TODO: #vNext: Make it proper async Task
/// <summary>
/// Exposes the elements FocusAsync() method.
/// </summary>
Expand All @@ -329,6 +330,7 @@ public async void FocusAsync()
await Element!.FocusAsync();
}

// TODO: #vNext: Make it proper async Task
/// <summary>
/// Exposes the elements FocusAsync(bool preventScroll) method.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/List/FluentAutocomplete.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<FluentInputLabel ForId="@Id" Label="@Label" AriaLabel="@GetAriaLabel()" ChildContent="@LabelTemplate" />

<FluentTextField role="combobox"
@ref="@Element"
Id="@Id"
AutoComplete="@AutoComplete"
Appearance="@Appearance"
Expand Down
5 changes: 4 additions & 1 deletion src/Core/Components/List/FluentAutocomplete.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
[CascadingTypeParameter(nameof(TOption))]
public partial class FluentAutocomplete<TOption> : ListComponentBase<TOption> where TOption : notnull
{
public const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/List/FluentAutocomplete.razor.js";
private string _valueText = string.Empty;

public const string JAVASCRIPT_FILE = "./_content/Microsoft.FluentUI.AspNetCore.Components/Components/List/FluentAutocomplete.razor.js";

public new FluentTextField? Element { get; set; } = default!;

/// <summary>
/// Initializes a new instance of the <see cref="FluentAutocomplete{TOption}"/> class.
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Components/TextField/FluentTextField.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await Module.InvokeVoidAsync("setAutocomplete", Id, AutoComplete);
}
}
if (DataList != null && !string.IsNullOrEmpty(Id))
{
Module ??= await JSRuntime.InvokeAsync<IJSObjectReference>("import", JAVASCRIPT_FILE);
await Module.InvokeVoidAsync("setDataList", Id, DataList);
}

}
}
12 changes: 12 additions & 0 deletions src/Core/Components/TextField/FluentTextField.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ export function setAutocomplete(id, value) {
if (!!fieldElement) {
fieldElement?.setAttribute("autocomplete", value);
}
}

export function setDataList(id, datalistid) {
const fieldElement = document.getElementById(id);
const dataList = document.getElementById(datalistid)?.cloneNode(true);

const shadowRoot = fieldElement.shadowRoot;
const shadowDataList = shadowRoot.getElementById(datalistid);
if (shadowDataList) {
shadowRoot.removeChild(shadowDataList);
}
shadowRoot.appendChild(dataList);
}

0 comments on commit 4b775a0

Please sign in to comment.