Skip to content
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

Autocomplete: fix keyboard navigation doesn't work for Tailwind #5531

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Source/Blazorise.Tailwind/Providers/TailwindClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,16 @@ public override string ToTextSizeType( TextSizeType textSizeType )

#endregion

#region Extensions

#region Autocomplete

public override string AutocompleteItemFocus( bool focus ) => focus ? "bg-gray-100 dark:bg-gray-600" : null;

#endregion

#endregion

public override bool UseCustomInputStyles { get; set; } = true;

public override string Provider => "Tailwind";
Expand Down
6 changes: 2 additions & 4 deletions Source/Blazorise/Base/BaseComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,12 @@ protected virtual void DirtyStyles()
/// <summary>
/// Gets or sets the classname provider.
/// </summary>
[Inject]
protected IClassProvider ClassProvider { get; set; }
[Inject] protected IClassProvider ClassProvider { get; set; }

/// <summary>
/// Gets or sets the style provider.
/// </summary>
[Inject]
protected IStyleProvider StyleProvider { get; set; }
[Inject] protected IStyleProvider StyleProvider { get; set; }

/// <summary>
/// Gets or sets the IJSUtilitiesModule reference.
Expand Down
10 changes: 10 additions & 0 deletions Source/Blazorise/Interfaces/IClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,16 @@ public interface IClassProvider

#endregion

#region Extensions

#region Autocomplete

string AutocompleteItemFocus( bool focus );

#endregion

#endregion

/// <summary>
/// Enables a custom css for select/check/radio/file inputs.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Source/Blazorise/Providers/ClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,16 @@ public virtual string ToTableColumnFixedPosition( TableColumnFixedPosition table

#endregion

#region Extensions

#region Autocomplete

public virtual string AutocompleteItemFocus( bool focus ) => focus ? "focus" : null;

#endregion

#endregion

public abstract bool UseCustomInputStyles { get; set; }

public abstract string Provider { get; }
Expand Down
10 changes: 10 additions & 0 deletions Source/Blazorise/Providers/EmptyClassProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,16 @@ class EmptyClassProvider : IClassProvider

#endregion

#region Extensions

#region Autocomplete

public string AutocompleteItemFocus( bool focus ) => null;

#endregion

#endregion

#region Properties

public bool UseCustomInputStyles { get; set; } = false;
Expand Down
12 changes: 10 additions & 2 deletions Source/Blazorise/wwwroot/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,18 @@ export function scrollElementIntoView(elementId, smooth) {
top = element.offsetTop + element.offsetHeight - element.parentElement.clientHeight;
}

var behavior = smooth ? "smooth" : "instant";
element.parentElement.scrollTo({ top: top, behavior: behavior });
var scrollableParent = getScrollableParent(element);

if (scrollableParent) {
var behavior = smooth ? "smooth" : "instant";
scrollableParent.scrollTo({ top: top, behavior: behavior });
}
}
}
function getScrollableParent(el) {
while ((el = el.parentElement) && window.getComputedStyle(el).overflowY.indexOf('scroll') === -1);
return el;
}

// sets the value to the element property
export function setProperty(element, property, value) {
Expand Down
7 changes: 6 additions & 1 deletion Source/Extensions/Blazorise.Components/Autocomplete.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ protected string DropdownClassNames
/// Gets the custom class-names for dropdown element.
/// </summary>
protected string DropdownItemClassNames( int index )
=> $"b-is-autocomplete-suggestion {( ActiveItemIndex == index ? "focus" : string.Empty )} {( SelectionMode == AutocompleteSelectionMode.Checkbox ? "b-is-autocomplete-suggestion-checkbox" : string.Empty )}";
=> $"b-is-autocomplete-suggestion {ClassProvider.AutocompleteItemFocus( ActiveItemIndex == index )} {( SelectionMode == AutocompleteSelectionMode.Checkbox ? "b-is-autocomplete-suggestion-checkbox" : string.Empty )}";

/// <summary>
/// Provides an index based id for the dropdown suggestion items.
Expand All @@ -1245,6 +1245,11 @@ protected string DropdownItemId( int index )
protected bool IsMultiple => Multiple || SelectionMode == AutocompleteSelectionMode.Multiple || SelectionMode == AutocompleteSelectionMode.Checkbox;
#pragma warning restore CS0618 // Type or member is obsolete

/// <summary>
/// Gets or sets the classname provider.
/// </summary>
[Inject] protected IClassProvider ClassProvider { get; set; }

/// <summary>
/// Gets or sets the <see cref="IJSClosableModule"/> instance.
/// </summary>
Expand Down
Loading