-
Notifications
You must be signed in to change notification settings - Fork 3
refactor(ui): SearchField 공통 스타일 분리 및 종속성 제거 #644
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
frontend/src/components/common/SearchField/SearchField.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import React, { useRef, useState } from 'react'; | ||
| import * as Styled from '@/components/common/SearchField/SearchField.styles'; | ||
| import searchButtonIcon from '@/assets/images/icons/search_button_icon.svg'; | ||
|
|
||
| interface SearchFieldProps { | ||
| value: string; | ||
| onChange: (value: string) => void; | ||
| onSubmit: () => void; | ||
| placeholder?: string; | ||
| ariaLabel?: string; | ||
| autoBlur?: boolean; | ||
| } | ||
|
|
||
| const SearchField = ({ | ||
| value, | ||
| onChange, | ||
| onSubmit, | ||
| placeholder = '검색어를 입력하세요', | ||
| ariaLabel = '검색 입력창', | ||
| autoBlur = true, | ||
| }: SearchFieldProps) => { | ||
| const [isFocused, setIsFocused] = useState(false); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { | ||
| e.preventDefault(); | ||
| onSubmit(); | ||
| if (autoBlur) inputRef.current?.blur(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Styled.SearchBoxContainer $isFocused={isFocused} onSubmit={handleSubmit}> | ||
| <Styled.SearchInputStyles | ||
| ref={inputRef} | ||
| type='text' | ||
| placeholder={placeholder} | ||
| value={value} | ||
| onChange={(e) => onChange(e.target.value)} | ||
| onFocus={() => setIsFocused(true)} | ||
| onBlur={() => setIsFocused(false)} | ||
| aria-label={ariaLabel} | ||
| /> | ||
| <Styled.SearchButton | ||
| type='submit' | ||
| $isFocused={isFocused} | ||
| aria-label='검색' | ||
| > | ||
| <img src={searchButtonIcon} alt='Search Button' /> | ||
| </Styled.SearchButton> | ||
| </Styled.SearchBoxContainer> | ||
| ); | ||
| }; | ||
|
|
||
| export default SearchField; | ||
43 changes: 43 additions & 0 deletions
43
frontend/src/pages/MainPage/components/SearchBox/SearchBox.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { useSearch } from '@/context/SearchContext'; | ||
| import { useCategory } from '@/context/CategoryContext'; | ||
| import useMixpanelTrack from '@/hooks/useMixpanelTrack'; | ||
| import SearchField from '@/components/common/SearchField/SearchField'; | ||
| import { useLocation, useNavigate } from 'react-router-dom'; | ||
|
|
||
| const SearchBox = () => { | ||
| const { setKeyword, inputValue, setInputValue, setIsSearching } = useSearch(); | ||
| const { setSelectedCategory } = useCategory(); | ||
| const trackEvent = useMixpanelTrack(); | ||
| const navigate = useNavigate(); | ||
| const location = useLocation(); | ||
|
|
||
| const redirectToHome = () => { | ||
| if (location.pathname !== '/') { | ||
| navigate('/'); | ||
| } | ||
| }; | ||
|
|
||
| const handleSearch = () => { | ||
| redirectToHome(); | ||
| setKeyword(inputValue); | ||
| setSelectedCategory('all'); | ||
| setIsSearching(true); | ||
|
|
||
| trackEvent('Search Executed', { | ||
| inputValue: inputValue, | ||
| page: window.location.pathname, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <SearchField | ||
| value={inputValue} | ||
| onChange={(v) => setInputValue(v)} | ||
| onSubmit={handleSearch} | ||
| placeholder='어떤 동아리를 찾으세요?' | ||
| ariaLabel='동아리 검색창' | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default SearchBox; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
컨테이너 요소가 form인지 확인 필요 — onSubmit 동작/엔터 제출 보장 위해 as='form'과 role='search' 지정 권장
Styled.SearchBoxContainer가 styled.form이 아니라면 onSubmit이 동작하지 않습니다. 안전하게 as='form'과 role='search'를 명시하세요.
또는 SearchField.styles.ts에서 SearchBoxContainer를 styled.form으로 선언되어 있는지 확인해 주세요.
🏁 Script executed:
Length of output: 446
Search 역할 명시를 위해 role="search" 추가 필요
현재
SearchBoxContainer는styled.form으로 정의되어 있어onSubmit은 정상적으로 동작합니다. 그러나 접근성(ARIA) 향상을 위해role="search"속성을 추가하세요.대상 파일:
frontend/src/components/common/SearchField/SearchField.tsx라인: 31–33
📝 Committable suggestion
🤖 Prompt for AI Agents