Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
Todo-Storybook
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Madhankumar
Todo-Storybook
Commits
4b7404c7
Commit
4b7404c7
authored
Sep 21, 2023
by
Madhankumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
textarea height issue
parent
5a52d8a6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
31 deletions
+52
-31
db.json
db.json
+3
-3
index.js
src/app-context/index.js
+2
-2
index.js
src/components/base/layout/index.js
+5
-4
layout.css
src/components/base/layout/layout.css
+10
-5
index.js
src/components/top-level/form/index.js
+1
-1
index.js
src/components/top-level/task/index.js
+25
-13
task.css
src/components/top-level/task/task.css
+6
-3
No files found.
db.json
View file @
4b7404c7
{
"task"
:
[
{
"title"
:
"
Travel to head office
"
,
"title"
:
""
,
"isCompleted"
:
false
,
"id"
:
1
},
{
"title"
:
"
Buy food
"
,
"isCompleted"
:
tru
e
,
"title"
:
""
,
"isCompleted"
:
fals
e
,
"id"
:
2
}
]
...
...
src/app-context/index.js
View file @
4b7404c7
...
...
@@ -18,9 +18,9 @@ export function TodoProvider({ children }) {
}
}
//UPDATE METHOD
async
function
updateTodo
({
id
,
...
item
})
{
async
function
updateTodo
({
id
,
title
,
isCompleted
})
{
try
{
const
response
=
await
api
.
updateTodo
({
id
,
...
item
});
const
response
=
await
api
.
updateTodo
({
id
,
title
,
isCompleted
});
setTodo
(
response
);
}
catch
(
err
)
{
toast
.
error
(
err
.
message
);
...
...
src/components/base/layout/index.js
View file @
4b7404c7
import
"./layout.css"
;
function
Layout
({
count
,
...
props
})
{
console
.
log
(
props
);
const
todoCount
=
count
>
1
?
"Todos"
:
"Todo"
;
return
(
<
div
className
=
"container"
>
<
h
2
>
You
have
{
count
}
{
count
>
1
?
"Todos"
:
"Todo"
}
<
/h
2
>
<
h
1
>
You
have
{
count
}
{
todoCount
}
<
/h
1
>
{
/* inner section that contain (tasklist and forms) */
}
<
div
{...
props
}
><
/div
>
<
/div
>
...
...
src/components/base/layout/layout.css
View file @
4b7404c7
.container
{
min-height
:
40vh
;
height
:
auto
;
min-height
:
40
dvh
;
margin-inline
:
auto
;
background
:
white
;
position
:
relative
;
}
.container
h
2
{
.container
h
1
{
box-shadow
:
rgba
(
0
,
0
,
0
,
0.04
)
0px
3px
5px
;
border
:
none
;
text-align
:
center
;
padding
:
1.3rem
0px
;
margin
:
0
;
position
:
relative
;
font-size
:
25px
;
z-index
:
1
;
}
h3
{
...
...
@@ -24,6 +23,12 @@ h3 {
}
@media
screen
and
(
min-width
:
1024px
)
{
.container
{
width
:
40
dvw
;
min-width
:
40
dvw
;
}
}
@media
screen
and
(
min-width
:
1550px
)
{
.container
{
min-width
:
30
dvw
;
}
}
src/components/top-level/form/index.js
View file @
4b7404c7
...
...
@@ -8,7 +8,7 @@ function Form({ onSubmit }) {
const
handleSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
onSubmit
({
title
});
//
setTitle("");
setTitle
(
""
);
};
return
(
...
...
src/components/top-level/task/index.js
View file @
4b7404c7
...
...
@@ -23,21 +23,35 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) {
// (useCallback)---> to avoid calling the checkbox component without any action applied on checkbox
const
handleChange
=
useCallback
(()
=>
{
setIsCheck
(
!
ischeck
);
onChange
({
id
,
title
,
isCompleted
:
!
ischeck
});
toast
.
success
(
`
${
!
ischeck
?
"Task completed"
:
"Task not completed"
}
`
,
"success"
);
onChange
({
id
,
isCompleted
:
!
ischeck
});
// toast(`${!ischeck ? "Task completed" : "Task not completed"}`, "success");
},
[
ischeck
]);
const
handleContent
=
(
e
)
=>
{
setDebounceTitle
(
e
.
target
.
value
);
const
textarea
=
document
.
querySelector
(
"textarea"
);
//calculate the height of content based on scrollheight
textarea
.
addEventListener
(
"keyup"
,
(
e
)
=>
{
let
scheight
=
e
.
target
.
scrollHeight
;
textarea
.
style
.
height
=
`
${
scheight
}
px`
;
const
textareaRef
=
textarea_ref
.
current
;
textareaRef
.
addEventListener
(
"input"
,
function
()
{
this
.
style
.
height
=
"auto"
;
// Reset the height to auto to calculate the correct scrollHeight
const
scrollHeight
=
this
.
scrollHeight
;
if
(
this
.
scrollTop
===
0
)
{
this
.
style
.
height
=
`
${
scrollHeight
}
px`
;
}
else
{
// If there is overflow (a new line is created), increase the height
this
.
style
.
height
=
`
${
scrollHeight
+
this
.
scrollTop
}
px`
;
}
});
// Optional: To ensure the textarea resizes initially if there's content
textareaRef
.
dispatchEvent
(
new
Event
(
"input"
));
//const textarea = document.querySelector("textarea");
//calculate the height of content based on scrollheight
// textarea.addEventListener("keyup", (e) => {
// let scheight = e.target.scrollHeight;
// textarea.style.height = `${scheight}px`;
// });
};
//debounce
...
...
@@ -45,11 +59,10 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) {
//checking the content height and set on page load
const
scrollHeight
=
textarea_ref
.
current
.
scrollHeight
;
textarea_ref
.
current
.
style
.
height
=
`
${
scrollHeight
}
px`
;
//after 2 second it will execute
const
handler
=
setTimeout
(()
=>
{
if
(
textarea_ref
.
current
.
value
!==
title
)
{
onChange
({
id
,
title
:
debouncetitle
,
isCompleted
:
!
ischeck
});
onChange
({
id
,
title
:
debouncetitle
});
toast
.
success
(
"Task updated"
);
}
},
2000
);
...
...
@@ -71,7 +84,6 @@ function Task({ id = 1, title, isCompleted, onChange, onDelete }) {
<
textarea
ref
=
{
textarea_ref
}
className
=
{
`
${
ischeck
?
"strike-through"
:
""
}
`
}
contentEditable
=
{
true
}
value
=
{
debouncetitle
}
onChange
=
{
handleContent
}
// disabled={ischeck}
...
...
src/components/top-level/task/task.css
View file @
4b7404c7
.task-section
{
display
:
flex
;
align-items
:
center
;
padding
:
0.
3rem
0.8
rem
;
padding
:
0.
5rem
1rem
0.4rem
1
rem
;
justify-content
:
space-between
;
border-top
:
1px
solid
#ccc
;
/* box-shadow: rgba(0, 0, 0, 0.06) 0px 2px 4px 0px inset; */
clip-path
:
inset
(
0
-100vmax
);
}
...
...
@@ -13,6 +14,7 @@
.task-section
>
div
{
display
:
flex
;
align-items
:
center
;
height
:
auto
;
width
:
90%
;
}
.fa-close
{
...
...
@@ -34,8 +36,9 @@ input:focus {
resize
:
none
;
border
:
none
;
outline
:
none
;
margin
:
20px
0px
0px
5px
;
padding
:
0
;
position
:
relative
;
top
:
10px
;
margin-left
:
0.4rem
;
font-size
:
17px
;
color
:
#8e8d8d
;
font-family
:
"Open Sans"
,
sans-serif
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment