kahuna-base-react-components 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -124,6 +124,7 @@ interface KTextAreaProps {
124
124
  iconSize?: string;
125
125
  checked?: boolean;
126
126
  maxHeight?: number;
127
+ clearTextOnPressedEnter?: boolean;
127
128
  }
128
129
  declare const KTextArea: React.FC<KTextAreaProps>;
129
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kahuna-base-react-components",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Kahuna Base React Components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -24,14 +24,18 @@ KTextAreaPrimary.args = {
24
24
  if (event.key === "Enter") {
25
25
  console.log("Enter is clicked and our value is:", event.currentTarget)
26
26
  }
27
+ if (event.key === "Enter" && event.shiftKey) {
28
+ console.log("Enter and shift is clicked ")
29
+ }
27
30
  },
28
31
  placeholder: "Placeholder...",
29
32
  hoverBackground: "white",
30
33
  width: 200,
31
34
  height: 20,
32
35
  leftIcon: TracksIcon,
33
- activeBackground: "#FFF"
34
-
36
+ activeBackground: "#FFF",
37
+ maxHeight: 200,
38
+ clearTextOnPressedEnter: true
35
39
  }
36
40
 
37
41
  export const KTextAreaLeftIcon = Template.bind({})
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState, KeyboardEvent } from "react"
1
+ import React, { useEffect, useState, KeyboardEvent, useRef } from "react"
2
2
  import "../../main.css"
3
3
 
4
4
  export interface KTextAreaProps {
@@ -29,12 +29,15 @@ export interface KTextAreaProps {
29
29
  iconSize?: string
30
30
  checked?: boolean
31
31
  maxHeight?: number
32
+ clearTextOnPressedEnter?: boolean
32
33
  }
33
34
 
34
35
  const KTextArea: React.FC<KTextAreaProps> = (props) => {
35
36
  const [background, setBackground] = useState("#F5F5F5")
36
37
  const [hover, setHover] = useState(false)
37
38
 
39
+ const textAreaRef = useRef<HTMLTextAreaElement>(null)
40
+
38
41
  useEffect(() => {
39
42
  const emptyBackground = props.background || "#F5F5F5"
40
43
  const activeBackground = props.activeBackground || "#FFF"
@@ -63,11 +66,14 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
63
66
 
64
67
  const autoResize = props.maxHeight && props.maxHeight !== props.height
65
68
  const maxHeight = props.maxHeight || 200
69
+ const clearTextOnPressedEnter = props.clearTextOnPressedEnter || false
66
70
 
67
71
  const handleInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
68
- const textarea = e.target
69
- textarea.style.height = "auto"
70
- textarea.style.height = `${textarea.scrollHeight}px` // Set the height to scrollHeight
72
+ if (textAreaRef.current) {
73
+ const textarea = textAreaRef.current
74
+ textarea.style.height = "auto"
75
+ textarea.style.height = `${textarea.scrollHeight}px` // Set the height to scrollHeight
76
+ }
71
77
  }
72
78
 
73
79
  return (
@@ -93,6 +99,7 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
93
99
  )}
94
100
 
95
101
  <textarea
102
+ ref={textAreaRef}
96
103
  className={"k-input"}
97
104
  style={{
98
105
  background: hover ? hoverBackground : background,
@@ -121,6 +128,20 @@ const KTextArea: React.FC<KTextAreaProps> = (props) => {
121
128
  }}
122
129
  onKeyDown={(event) => {
123
130
  if (props.onKeyDown) props.onKeyDown(event)
131
+
132
+ if (event.key === "Enter") {
133
+ if (event.shiftKey) {
134
+ return
135
+ } else if (textAreaRef.current && clearTextOnPressedEnter) {
136
+ event.preventDefault()
137
+ const textAreaComponent = textAreaRef.current
138
+ textAreaComponent.style.height = "auto"
139
+ textAreaComponent.style.height = `${height}px`
140
+ textAreaComponent.value = ""
141
+ } else {
142
+ event.preventDefault()
143
+ }
144
+ }
124
145
  }}
125
146
  />
126
147