Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/remove emoji from textfield #346

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flipper-ui",
"version": "0.31.4",
"version": "0.31.5",
"description": "",
"main": "dist/index.js",
"homepage": "https://flipper-ui.ngi.com.br/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`DateTime should match snapshot 1`] = `
class="MuiInputBase-input MuiOutlinedInput-input makeStyles-outlinedInput-49 MuiInputBase-inputAdornedEnd MuiOutlinedInput-inputAdornedEnd"
role="date-picker"
type="text"
value="15032024"
value="03042024"
/>
<div
class="MuiInputAdornment-root MuiInputAdornment-positionEnd"
Expand Down
27 changes: 24 additions & 3 deletions src/core/inputs/text-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const TextField = ({
fullWidth,
hasClear,
onClear,
onChange,
characters,
children,
...otherProps
Expand All @@ -233,16 +234,16 @@ export const TextField = ({
}
})

const classes = useStyles()
const clearClass = clearStyle()

const hasValue = !!otherProps.value

const endAdornment =
hasValue && hasClear
? { endAdornment: renderEndAdornment(onClear) }
: {}

const classes = useStyles()
const clearClass = clearStyle()

const handleClick = () => {
if (onHelperClick) {
onHelperClick()
Expand All @@ -251,6 +252,25 @@ export const TextField = ({

const Wrapper = hasClear ? StaticTextFieldWrapper : TextFieldWrapper

const emojiRegex =
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g

const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
if (onChange) {
const inputValue = event.target.value

if (emojiRegex.test(inputValue)) {
const newValue = inputValue.replace(emojiRegex, '')

event.target.value = newValue

return onChange(event)
}

return onChange(event)
}
}

return (
<Wrapper>
<MuiTextField
Expand Down Expand Up @@ -295,6 +315,7 @@ export const TextField = ({
...SelectProps
}}
characters={characters?.toString()}
onChange={handleInputChange}
{...otherProps}>
{options ? renderOptions(options, classes) : children}
</MuiTextField>
Expand Down
Loading