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

fix: Add icon to masked textfield component #1536 #1539

Merged
merged 4 commits into from
Jul 18, 2022
Merged
Changes from all 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
54 changes: 26 additions & 28 deletions ui/src/textbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,48 +70,46 @@ export interface Textbox {
const DEBOUNCE_TIMEOUT = 500
export const
XTextbox = ({ model: m }: { model: Textbox }) => {
const onChange = ({ target }: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, v?: S) => {
v = v || (target as HTMLInputElement).value
const
onChange = ({ target }: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>, v?: S) => {
v = v || (target as HTMLInputElement).value

wave.args[m.name] = v ?? (m.value || '')
if (m.trigger) wave.push()
}
wave.args[m.name] = v ?? (m.value || '')
if (m.trigger) wave.push()
},
textFieldProps: Fluent.ITextFieldProps & { 'data-test': S } = {
'data-test': m.name,
label: m.label,
value: m.value,
errorMessage: m.error,
required: m.required,
disabled: m.disabled,
readOnly: m.readonly,
onChange: m.trigger ? debounce(DEBOUNCE_TIMEOUT, onChange) : onChange,
iconProps: { iconName: m.icon },
placeholder: m.placeholder,
prefix: m.prefix,
suffix: m.suffix,
defaultValue: m.value,
multiline: m.multiline,
spellCheck: m.spellcheck,
type: m.password ? 'password' : undefined,
}

// eslint-disable-next-line react-hooks/exhaustive-deps
React.useEffect(() => { wave.args[m.name] = m.value || '' }, [])

return m.mask
? (
<Fluent.MaskedTextField
data-test={m.name}
label={m.label}
value={m.value}
mask={m.mask}
errorMessage={m.error}
required={m.required}
disabled={m.disabled}
readOnly={m.readonly}
onChange={m.trigger ? debounce(DEBOUNCE_TIMEOUT, onChange) : onChange}
{...textFieldProps}
/>
)
: (
<Fluent.TextField
data-test={m.name}
styles={m.multiline && m.height ? { field: { height: m.height }, fieldGroup: { minHeight: m.height } } : undefined}
label={m.label}
placeholder={m.placeholder}
iconProps={{ iconName: m.icon }}
prefix={m.prefix}
suffix={m.suffix}
defaultValue={m.value}
errorMessage={m.error}
required={m.required}
disabled={m.disabled}
readOnly={m.readonly}
multiline={m.multiline}
spellCheck={m.spellcheck}
type={m.password ? 'password' : undefined}
onChange={m.trigger ? debounce(DEBOUNCE_TIMEOUT, onChange) : onChange}
{...textFieldProps}
/>
)
}