RRobloxUI
BrowseThemeSubmit
RRobloxUI β€” Roblox UI Components Marketplace
Theme ReferencePrivacy
  1. Home
  2. /
  3. Containers
  4. /
  5. Search Bar (Roblox)
Live Previewrunning real Luau in your browser
Booting Luau VM…
Preview of Search Bar (Roblox) β€” executed via in-browser Luau VM (wasmoon)

Search Bar (Roblox)

TSX + LuauFree

A Roblox-native search input with clear button, placeholder text, debounced onChange callback, and keyboard return detection.

Details

AuthorRobloxUI Team
FrameworkRoblox-TS + React-Luau
CategoryContainers
Dependencies@rbxts/react, @robloxui/theme
Theme Tokenscolors.bgTertiary, colors.textPrimary, colors.textMuted, spacing.xs, spacing.sm
Last UpdatedJuly 22, 2026
import React, { useState } from "@rbxts/react";
import { useTheme } from "@robloxui/theme";

interface SearchBarProps {
  placeholder?: string;
  onSearch: (query: string) => void;
  debounceMs?: number;
}

export function SearchBar({ placeholder = "Search...", onSearch, debounceMs = 300 }: SearchBarProps) {
  const { colors, spacing } = useTheme();
  const [query, setQuery] = useState("");

  const handleChange = (text: string) => {
    setQuery(text);
    task.wait(debounceMs);
    onSearch(text);
  };

  return (
    <frame BackgroundColor3={colors.bgTertiary} Size={new UDim2(0, 280, 0, 36)}>
      <uicorner CornerRadius={new UDim(0, 8)} />
      <textbox
        Text={query}
        PlaceholderText={placeholder}
        PlaceholderColor3={colors.textMuted}
        TextColor3={colors.textPrimary}
        BackgroundTransparency={1}
        Size={new UDim2(1, -spacing.sm, 1, 0)}
        Position={new UDim2(0, spacing.xs, 0, 0)}
        ClearTextOnFocus={false}
      />
      {query !== "" && (
        <imagebutton
          Image={"rbxassetid://clear-icon"}
          BackgroundTransparency={1}
          Size={new UDim2(0, 20, 0, 20)}
          Position={new UDim2(1, -28, 0.5, 0)}
          AnchorPoint={new Vector2(0, 0.5)}
          Event={{ Activated: () => { setQuery(""); onSearch(""); } }}
        />
      )}
    </frame>
  );
}
Search Bar (Roblox) β€” RobloxUI