Skip to content
Closed
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
2 changes: 1 addition & 1 deletion frontend/src/components/common/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useLocation } from 'react-router-dom';
import * as Styled from './Header.styles';
import SearchBox from '@/components/common/SearchBox/SearchBox';
import SearchBox from '@/pages/MainPage/components/SearchBox/SearchBox';
import useHeaderService from '@/services/header/useHeaderService';
import useMobileMenu from '@/services/header/useMobileMenu';
import useIsMobile from '@/hooks/useIsMobile';
Expand Down
70 changes: 0 additions & 70 deletions frontend/src/components/common/SearchBox/SearchBox.tsx

This file was deleted.

54 changes: 54 additions & 0 deletions frontend/src/components/common/SearchField/SearchField.tsx
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
Comment on lines +31 to +33
Copy link
Contributor

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'를 명시하세요.

-  return (
-    <Styled.SearchBoxContainer $isFocused={isFocused} onSubmit={handleSubmit}>
+  return (
+    <Styled.SearchBoxContainer
+      as='form'
+      role='search'
+      $isFocused={isFocused}
+      onSubmit={handleSubmit}
+    >

또는 SearchField.styles.ts에서 SearchBoxContainer를 styled.form으로 선언되어 있는지 확인해 주세요.


🏁 Script executed:

#!/bin/bash
# Find the style file and inspect the definition of SearchBoxContainer
STYLE_FILE=$(fd SearchField.styles.ts)
echo "Found style file: $STYLE_FILE"
rg -n "SearchBoxContainer" "$STYLE_FILE"

Length of output: 446


Search 역할 명시를 위해 role="search" 추가 필요

현재 SearchBoxContainerstyled.form으로 정의되어 있어 onSubmit은 정상적으로 동작합니다. 그러나 접근성(ARIA) 향상을 위해 role="search" 속성을 추가하세요.

대상 파일: frontend/src/components/common/SearchField/SearchField.tsx
라인: 31–33

-  return (
-    <Styled.SearchBoxContainer $isFocused={isFocused} onSubmit={handleSubmit}>
+  return (
+    <Styled.SearchBoxContainer
+      role="search"
+      $isFocused={isFocused}
+      onSubmit={handleSubmit}
+    >
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (
<Styled.SearchBoxContainer $isFocused={isFocused} onSubmit={handleSubmit}>
<Styled.SearchInputStyles
return (
<Styled.SearchBoxContainer
role="search"
$isFocused={isFocused}
onSubmit={handleSubmit}
>
<Styled.SearchInputStyles
/* ...rest of props... */
🤖 Prompt for AI Agents
In frontend/src/components/common/SearchField/SearchField.tsx around lines 31 to
33, the SearchBoxContainer (a styled.form) needs the ARIA role added; update the
JSX to include role="search" on the Styled.SearchBoxContainer element (ensure
the prop passes through to the underlying form element and adjust any TS props
types if necessary so role is accepted).

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 frontend/src/pages/MainPage/components/SearchBox/SearchBox.tsx
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;