Appearance
In this article, you will find information about the styling options and rendering of the Kendo UI AutoComplete.
For a live example, visit the Appearance Demo of the AutoComplete.
Options
The Kendo UI AutoComplete supports the following styling options:
size—Configures the overall size of the component.rounded—Configures the border radius for the tags.fillMode—Controls how the color is applied.
Size
The size option controls how big or small the AutoComplete component looks. The structure of the class is k-input-{size}.
The following values are available for the size option:
sm—small sizemd—medium sizelg—large sizenone—unset
The default size value is medium and it is applied to the span wrapping element through the k-input-md class.
The example below shows a basic configuration and how to set size to "large":
<input id="autocomplete" />
<script>
$("#autocomplete").kendoAutoComplete({
size: "large"
});
</script>
Below is the HTML that is affected from the configuration. The changes are applied to the span.k-autocomplete wrapping element:
<span class="k-autocomplete k-input k-input-lg">
...
</span>
Rounded
The rounded option controls how much border radius is applied to the tags for the selected items in the widget. The structure of the class is k-rounded-{size}.
The following values are available for the rounded option:
sm—small border radiusmd—medium border radiuslg—large border radiusfull—ellipse-like border radiusnone—unset
The default value is medium and it is applied to the span.k-autocomplete wrapping element through the k-rounded-md class.
The example below shows a basic AutoComplete configuration and how to set rounded to "full":
<input id="autocomplete" />
<script>
$("#autocomplete").kendoAutoComplete({
rounded: "full"
});
</script>
The changes are applied to the span.k-autocomplete wrapping element:
<span class="k-autocomplete k-input k-rounded-full">
...
</span>
FillMode
The fillMode option controls how the color is applied. The structure of the class is k-input-{fillMode}.
The following values are available for the fillMode option:
solidflatoutlinenone
The default value is solid and it is applied to the span.k-autocomplete wrapping element through the k-input-solid class.
The example below shows a basic AutoComplete configuration and how to set fillMode to "outline":
<input id="autocomplete" />
<script>
$("#autocomplete").kendoAutoComplete({
fillMode: "outline"
});
</script>
The changes are applied to the span.k-autocomplete wrapping element:
<span class="k-autocomplete k-input k-input-outline">
...
</span>
Rendering
Starting with version R1 2022, the component has a new rendering. For additional information on the decision behind these changes, visit the Components Rendering Overview article.
To review the latest rendering of the component, refer to the HTML specifications in the Kendo UI Themes Monorepo. The tests folder of the repository contains the rendering for all flavors of the components, providing a clear reference for how their elements are structured. The rendering information can help you customize a component's appearance and behavior by applying custom CSS or JavaScript to suit specific design or functional requirements.
Setting the List Width
To customize the width of the AutoComplete list and change its dimensions, use the jQuery width() method.
<input id="autoComplete" />
<script>
$("#autoComplete").kendoAutoComplete();
var autoComplete = $("#autocomplete").data("kendoAutoComplete");
// Set the width of the drop-down list.
autoComplete.list.width(400);
</script>
Setting the Popup Width
You can enable the popup element to automatically adjust its width according to the length of the item label it displays. When the autoWidth option is set to true, the popup will display the content on a single line and will not wrap it up.
<input id="autocomplete" style="width: 100px;" />
<script>
$("#autocomplete").kendoAutoComplete({
autoWidth: true,
dataSource: {
data: ["Short item", "An item with really, really long text"]
}
});
</script>
Accessing list Elements
The AutoComplete list renders an ID attribute which is generated from the ID of the widget and the -list suffix. You can use the ID to style the element or to access a specific element inside the popup element.
If the AutoComplete has no ID, the
listelement will have noIDeither.
<input id="autocomplete">
<script>
$(document).ready(function() {
$("#autocomplete").kendoAutoComplete({
dataSource: ["Item1", "Item2"]
});
// The DIV popup element that holds the header and footer templates, and the suggestion options.
var popupElement = $("#autocomplete-list");
console.log(popupElement);
});
</script>
Removing Input Values
The AutoComplete enables you to remove the values from its input area by using the clearButton configuration option. As a result, an X button appears in the input area on hover and when clicked, it resets the value of the widget and triggers the change event. By default, clearButton is enabled and is set to true.