Skip to content

Commit

Permalink
Give input selectors a default placeholder
Browse files Browse the repository at this point in the history
Much better than the default "Select..."
  • Loading branch information
ivarnakken committed Oct 14, 2023
1 parent 11da240 commit 424a6f1
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/components/Form/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function createField(Component: ComponentType<any>, options?: Options) {
const hasError = showErrors && touched && anyError?.length > 0;
const hasWarning = showErrors && touched && warning?.length > 0;
const fieldName = input?.name;
const inlineLabel = options?.inlineLabel;
const { noLabel, inlineLabel } = options || {};

const labelComponent = (
<Flex alignItems="center">
Expand Down Expand Up @@ -137,6 +137,7 @@ export function createField(Component: ComponentType<any>, options?: Options) {
<Component
{...input}
{...props}
label={!noLabel && !inlineLabel && label}
onChange={(value) => {
input.onChange?.(value);
onChange?.(value);
Expand All @@ -163,7 +164,7 @@ export function createField(Component: ComponentType<any>, options?: Options) {

return (
<div className={cx(styles.field, fieldClassName)} style={fieldStyle}>
{options?.noLabel ? content : <label>{content}</label>}
{noLabel ? content : <label>{content}</label>}
{hasError && (
<RenderErrorMessage error={anyError} fieldName={fieldName} />
)}
Expand Down
8 changes: 6 additions & 2 deletions app/components/Form/SelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { GroupBase, StylesConfig, ThemeConfig } from 'react-select';

type Props = {
name: string;
label: string;
placeholder?: string;
multiple?: boolean;
tags?: boolean;
Expand Down Expand Up @@ -93,6 +94,7 @@ export const selectTheme = (

function SelectInput({
name,
label,
fetching,
selectStyle,
onBlur,
Expand All @@ -110,13 +112,15 @@ function SelectInput({
props.isMulti = true;
}

const defaultPlaceholder = `Velg ${label?.toLowerCase()}`;

if (creatable) {
return (
<div className={style.field}>
<Creatable
{...props}
isDisabled={disabled}
placeholder={!disabled && placeholder}
placeholder={!disabled && (placeholder || defaultPlaceholder)}
instanceId={name}
isMulti={props.isMulti}
onBlur={() => onBlur(value)}
Expand Down Expand Up @@ -144,7 +148,7 @@ function SelectInput({
<Select
{...props}
isDisabled={disabled}
placeholder={disabled ? 'Tomt' : placeholder}
placeholder={disabled ? 'Tomt' : placeholder || defaultPlaceholder}
instanceId={name}
shouldKeyDownEventCreateNewOption={shouldKeyDownEventCreateNewOption}
onBlur={() => onBlur(value)}
Expand Down
1 change: 0 additions & 1 deletion app/routes/admin/email/components/EmailUserEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const EmailUserEditor = ({
name="user"
required
disabled={emailUserId}
placeholder="Velg bruker"
filter={['users.user']}
component={SelectInput.AutocompleteField}
onChange={(data) => onUserChange(data as any as AutocompleteUserValue)}
Expand Down
1 change: 0 additions & 1 deletion app/routes/admin/groups/components/AddGroupMember.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const AddGroupMember = ({ submitting, handleSubmit }: Props) => {
<Field
label="Rolle"
name="role"
placeholder="Velg rolle"
options={roles}
component={SelectInput.Field}
/>
Expand Down
1 change: 0 additions & 1 deletion app/routes/contact/components/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const ContactForm = (props: Props) => {
</p>

<Field
placeholder="Velg mottaker"
label="Mottaker"
name="recipient_group"
value={hsRecipient}
Expand Down
2 changes: 1 addition & 1 deletion app/routes/events/EventCreateRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const mapStateToProps = (state, props) => {
eventType: '',
eventStatusType: {
value: 'TBA',
label: 'Ikke bestemt(TBA)',
label: 'Ikke bestemt (TBA)',
},
company: null,
responsibleGroup: null,
Expand Down
1 change: 1 addition & 0 deletions app/routes/events/components/EventEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ function EventEditor({
<div className={styles.subSection}>
<Field
name="canViewGroups"
placeholder="Velg grupper"
filter={['users.abakusgroup']}
fieldClassName={styles.metaField}
component={SelectInput.AutocompleteField}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ const SurveyEditor = ({
}}
>
<Field
placeholder="Velg arrangement"
label="Arrangement"
autoFocus={autoFocus}
name="event"
Expand Down

0 comments on commit 424a6f1

Please sign in to comment.