ライブデモ Live Demo
検索ボックスに文字を入力すると、マッチする候補がリアルタイムで表示されます。
例:「Button」「Input」「Label」など入力してみてください。
Type in the search box to see matching suggestions appear in real time.
Try
typing "Button", "Input", or "Label".
AI向け説明 AI Description
`F-005` はテキスト入力時にフィルタリングされたサジェストリストを表示する検索UIです。`max-height` と `opacity` のCSSトランジションで滑らかに表示され、JavaScriptで入力値に基づくフィルタリングとマッチ部分のハイライトを行います。
`F-005` renders a filtered suggestion list as the user types into a search input. CSS `max-height` and `opacity` transitions handle smooth reveal, while JavaScript filters suggestions and highlights matching text.
調整可能パラメータ Adjustable Parameters
- --suggestion-max-height — サジェストリストの最大高さMax height of suggestion list
- --highlight-color — マッチテキストのハイライト色Matched text highlight color
実装 Implementation
HTML + CSS + JS
<div class="search-wrapper">
<span class="search-icon">🔍</span>
<input type="text" class="search-input" id="search" autocomplete="off" />
<div class="suggestions" id="suggestions"></div>
</div>
<style>
:root {
--highlight-color: #5c6ac4;
--suggestion-max-height: 300px;
}
</style>
<script>
// (Filtering logic omitted for brevity)
</script>
React (JSX + CSS)
// react/F-005.jsx
import { useState } from 'react';
import './F-005.css';
export default function SearchWithSuggestions({ items = [], placeholder = '検索...' }) {
const [query, setQuery] = useState('');
const matches = query ? items.filter(i => i.toLowerCase().includes(query.toLowerCase())) : [];
return (
<div className="search-wrapper">
<span className="search-icon">🔍</span>
<input className="search-input" value={query} onChange={e => setQuery(e.target.value)} placeholder={placeholder} />
<div className={`suggestions ${matches.length ? 'open' : ''}`}>
{matches.map(m => <div key={m} className="suggestion-item" onClick={() => setQuery(m)}>{m}</div>)}
</div>
</div>
);
}
/* react/F-005.css */
/* F-005: Search with Suggestions */
.search-wrapper {
position: relative;
}
.search-input {
width: 100%;
padding: 14px 16px 14px 44px;
font-size: 16px;
border: 2px solid #e0e4f0;
border-radius: 12px;
outline: none;
transition: border-color 0.3s ease;
font-family: inherit;
}
.search-input:focus {
border-color: #5c6ac4;
box-shadow: 0 0 0 3px rgba(92, 106, 196, 0.15);
}
.search-icon {
position: absolute;
left: 14px;
top: 50%;
transform: translateY(-50%);
font-size: 18px;
color: #999;
pointer-events: none;
}
.suggestions {
position: absolute;
top: calc(100% + 4px);
left: 0;
right: 0;
border: 1px solid #e0e4f0;
border-radius: 12px;
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease, opacity 0.3s ease;
opacity: 0;
z-index: 10;
background: #fff;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
.suggestions.open {
max-height: 300px;
opacity: 1;
}
.suggestion-item {
padding: 12px 16px;
cursor: pointer;
transition: background 0.2s ease;
display: flex;
align-items: center;
gap: 10px;
}
.suggestion-item:hover {
background: #f5f7ff;
}
.suggestion-item mark {
background: rgba(92, 106, 196, 0.2);
color: #5c6ac4;
font-weight: 600;
border-radius: 2px;
padding: 0 2px;
}
AIへの指示テンプレート AI Prompt Template
以下のテンプレートをコピーしてAIアシスタントに貼り付けると、このパターンの実装を依頼できます。 Copy the template below and paste it into your AI assistant to request an implementation of this pattern.