Skip to content

Commit 884b7de

Browse files
Merge pull request #346 from nginformatica/feat/remove-emoji-from-textfield
feat/remove emoji from textfield
2 parents a647580 + 1e73f7d commit 884b7de

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flipper-ui",
3-
"version": "0.31.4",
3+
"version": "0.31.5",
44
"description": "",
55
"main": "dist/index.js",
66
"homepage": "https://flipper-ui.ngi.com.br/",

src/core/inputs/date-time/__snapshots__/date-time.spec.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports[`DateTime should match snapshot 1`] = `
1414
class="MuiInputBase-input MuiOutlinedInput-input makeStyles-outlinedInput-49 MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd"
1515
role="date-picker"
1616
type="text"
17-
value="15032024"
17+
value="03042024"
1818
/>
1919
<div
2020
class="MuiInputAdornment-root MuiInputAdornment-positionEnd"

src/core/inputs/text-field/__snapshots__/text-field.spec.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports[`TextField should match snapshot 1`] = `
1515
>
1616
<div
1717
aria-haspopup="listbox"
18-
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiSelect-outlined MuiInputBase-input MuiOutlinedInput-input makeStyles-outlinedInput-100 MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd"
18+
class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiSelect-outlined MuiInputBase-input MuiOutlinedInput-input makeStyles-outlinedInput-112 MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd"
1919
role="button"
2020
tabindex="0"
2121
>
@@ -31,7 +31,7 @@ exports[`TextField should match snapshot 1`] = `
3131
/>
3232
<svg
3333
aria-hidden="true"
34-
class="MuiSvgIcon-root MuiSelect-icon MuiSelect-iconOutlined makeStyles-iconOutlined-104"
34+
class="MuiSvgIcon-root MuiSelect-icon MuiSelect-iconOutlined makeStyles-iconOutlined-116"
3535
focusable="false"
3636
viewBox="0 0 24 24"
3737
>
@@ -71,11 +71,11 @@ exports[`TextField should match snapshot 1`] = `
7171
</div>
7272
<fieldset
7373
aria-hidden="true"
74-
class="PrivateNotchedOutline-root-105 MuiOutlinedInput-notchedOutline"
74+
class="PrivateNotchedOutline-root-117 MuiOutlinedInput-notchedOutline"
7575
style="padding-left: 8px;"
7676
>
7777
<legend
78-
class="PrivateNotchedOutline-legend-106"
78+
class="PrivateNotchedOutline-legend-118"
7979
style="width: 0.01px;"
8080
>
8181
<span>

src/core/inputs/text-field/index.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export const TextField = ({
221221
fullWidth,
222222
hasClear,
223223
onClear,
224+
onChange,
224225
characters,
225226
children,
226227
...otherProps
@@ -233,16 +234,16 @@ export const TextField = ({
233234
}
234235
})
235236

237+
const classes = useStyles()
238+
const clearClass = clearStyle()
239+
236240
const hasValue = !!otherProps.value
237241

238242
const endAdornment =
239243
hasValue && hasClear
240244
? { endAdornment: renderEndAdornment(onClear) }
241245
: {}
242246

243-
const classes = useStyles()
244-
const clearClass = clearStyle()
245-
246247
const handleClick = () => {
247248
if (onHelperClick) {
248249
onHelperClick()
@@ -251,6 +252,25 @@ export const TextField = ({
251252

252253
const Wrapper = hasClear ? StaticTextFieldWrapper : TextFieldWrapper
253254

255+
const emojiRegex =
256+
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g
257+
258+
const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
259+
if (onChange) {
260+
const inputValue = event.target.value
261+
262+
if (emojiRegex.test(inputValue)) {
263+
const newValue = inputValue.replace(emojiRegex, '')
264+
265+
event.target.value = newValue
266+
267+
return onChange(event)
268+
}
269+
270+
return onChange(event)
271+
}
272+
}
273+
254274
return (
255275
<Wrapper>
256276
<MuiTextField
@@ -295,6 +315,7 @@ export const TextField = ({
295315
...SelectProps
296316
}}
297317
characters={characters?.toString()}
318+
onChange={handleInputChange}
298319
{...otherProps}>
299320
{options ? renderOptions(options, classes) : children}
300321
</MuiTextField>

src/core/inputs/text-field/text-field.spec.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ describe('TextField', () => {
153153
})
154154
})
155155

156+
it('should remove emojis if typed', () => {
157+
render(<TextField inputProps={{ placeholder: 'Description' }} />)
158+
159+
const inputElement = screen.getByPlaceholderText(
160+
'Description'
161+
) as HTMLInputElement
162+
163+
fireEvent.change(inputElement, { target: { value: 'Hello World😀' } })
164+
165+
expect(inputElement.value).toBe('Hello World')
166+
})
167+
156168
it('should match snapshot', () => {
157169
const { container } = render(
158170
<TextField

0 commit comments

Comments
 (0)