Skip to content

Commit

Permalink
Merge pull request #152 from 2024WISCOM/feature/guestbook
Browse files Browse the repository at this point in the history
🐛 MaxLength 함수 추가
  • Loading branch information
nadomola authored Oct 27, 2024
2 parents 0e13134 + 83ae457 commit d895a45
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/guestBook/MessageInputSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MessageInputSection = ({ onSendMessage, onViewGuestBook }) => {

useEffect(()=> {
const handleResize =() => {
setIsMobile(window.innerWidth <=767);
setIsMobile(window.innerWidth <=768);
};

window.addEventListener('resize', handleResize);
Expand All @@ -31,6 +31,13 @@ const MessageInputSection = ({ onSendMessage, onViewGuestBook }) => {
setNewMessage({ to: '', from: '', message: '' });
};

const maxLengthCheck = (e) =>{
const {maxLength, value} = e.target;
if(value.length>maxLength){
e.target.value = value.slice(0,maxLength);
}
};

const handleViewGuestBook = () => {
if(messageGridRef.current){ // messageGrid 존재 유무 확인
messageGrid.scrollIntoView({ behavior: 'smooth' }); // 부드러운 스크롤
Expand Down Expand Up @@ -65,6 +72,7 @@ const MessageInputSection = ({ onSendMessage, onViewGuestBook }) => {
placeholder="받는 사람"
value={newMessage.to}
onChange={(e) => setNewMessage({ ...newMessage, to: e.target.value })}
onInput={maxLengthCheck}
maxLength={8}
/>
</Label>
Expand All @@ -82,6 +90,7 @@ const MessageInputSection = ({ onSendMessage, onViewGuestBook }) => {
placeholder="보내는 사람"
value={newMessage.from}
onChange={(e) => setNewMessage({ ...newMessage, from: e.target.value })}
onInput={maxLengthCheck}
maxLength={8}
/>
</Label>
Expand Down

0 comments on commit d895a45

Please sign in to comment.