[ui][typeahead] fix nullable prop (#492)

pull/493/head
Jeff Sieu 2 years ago committed by GitHub
parent ea57743cfe
commit 47bc5fb154
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -106,7 +106,6 @@ export default function LandingComponent({
isLabelHidden={true} isLabelHidden={true}
value={company} value={company}
onSelect={(value) => { onSelect={(value) => {
// @ts-ignore TODO(questions): handle potentially null value.
handleChangeCompany(value); handleChangeCompany(value);
}} }}
/> />
@ -115,7 +114,6 @@ export default function LandingComponent({
isLabelHidden={true} isLabelHidden={true}
value={location} value={location}
onSelect={(value) => { onSelect={(value) => {
// @ts-ignore TODO(questions): handle potentially null value.
handleChangeLocation(value); handleChangeLocation(value);
}} }}
/> />

@ -128,7 +128,6 @@ export default function ContributeQuestionForm({
{...field} {...field}
required={true} required={true}
onSelect={(option) => { onSelect={(option) => {
// @ts-ignore TODO(questions): handle potentially null value.
field.onChange(option); field.onChange(option);
}} }}
/> />
@ -164,7 +163,6 @@ export default function ContributeQuestionForm({
<CompanyTypeahead <CompanyTypeahead
{...field} {...field}
required={true} required={true}
// @ts-ignore TODO(questions): handle potentially null value.
onSelect={({ id }) => { onSelect={({ id }) => {
field.onChange(id); field.onChange(id);
}} }}
@ -181,7 +179,6 @@ export default function ContributeQuestionForm({
{...field} {...field}
required={true} required={true}
onSelect={(option) => { onSelect={(option) => {
// @ts-ignore TODO(questions): handle potentially null value.
field.onChange(option); field.onChange(option);
}} }}
/> />

@ -52,7 +52,6 @@ export default function CreateQuestionEncounterForm({
placeholder="Company" placeholder="Company"
// TODO: Fix suggestions and set count back to 3 // TODO: Fix suggestions and set count back to 3
suggestedCount={0} suggestedCount={0}
// @ts-ignore TODO(questions): handle potentially null value.
onSelect={({ value: company }) => { onSelect={({ value: company }) => {
setSelectedCompany(company); setSelectedCompany(company);
}} }}
@ -69,7 +68,6 @@ export default function CreateQuestionEncounterForm({
isLabelHidden={true} isLabelHidden={true}
placeholder="Location" placeholder="Location"
suggestedCount={0} suggestedCount={0}
// @ts-ignore TODO(questions): handle potentially null value.
onSelect={(location) => { onSelect={(location) => {
setSelectedLocation(location); setSelectedLocation(location);
}} }}
@ -86,7 +84,6 @@ export default function CreateQuestionEncounterForm({
isLabelHidden={true} isLabelHidden={true}
placeholder="Role" placeholder="Role"
suggestedCount={0} suggestedCount={0}
// @ts-ignore TODO(questions): handle potentially null value.
onSelect={({ value: role }) => { onSelect={({ value: role }) => {
setSelectedRole(role); setSelectedRole(role);
}} }}

@ -8,7 +8,10 @@ import type { RequireAllOrNone } from '~/utils/questions/RequireAllOrNone';
type TypeaheadProps = ComponentProps<typeof Typeahead>; type TypeaheadProps = ComponentProps<typeof Typeahead>;
type TypeaheadOption = TypeaheadProps['options'][number]; type TypeaheadOption = TypeaheadProps['options'][number];
export type ExpandedTypeaheadProps = Omit<TypeaheadProps, 'onSelect'> & export type ExpandedTypeaheadProps = Omit<
TypeaheadProps,
'nullable' | 'onSelect'
> &
RequireAllOrNone<{ RequireAllOrNone<{
clearOnSelect?: boolean; clearOnSelect?: boolean;
filterOption: (option: TypeaheadOption) => boolean; filterOption: (option: TypeaheadOption) => boolean;
@ -59,8 +62,7 @@ export default function ExpandedTypeahead({
if (clearOnSelect) { if (clearOnSelect) {
setKey((key + 1) % 2); setKey((key + 1) % 2);
} }
// TODO: Remove onSelect null coercion once onSelect prop is refactored onSelect(option);
onSelect(option!);
}} }}
/> />
</div> </div>

@ -344,7 +344,6 @@ export default function QuestionsBrowsePage() {
isLabelHidden={true} isLabelHidden={true}
placeholder="Search companies" placeholder="Search companies"
onSelect={(option) => { onSelect={(option) => {
// @ts-ignore TODO(questions): handle potentially null value.
onOptionChange({ onOptionChange({
...option, ...option,
checked: true, checked: true,
@ -385,7 +384,6 @@ export default function QuestionsBrowsePage() {
isLabelHidden={true} isLabelHidden={true}
placeholder="Search roles" placeholder="Search roles"
onSelect={(option) => { onSelect={(option) => {
// @ts-ignore TODO(questions): handle potentially null value.
onOptionChange({ onOptionChange({
...option, ...option,
checked: true, checked: true,
@ -446,7 +444,6 @@ export default function QuestionsBrowsePage() {
isLabelHidden={true} isLabelHidden={true}
placeholder="Search locations" placeholder="Search locations"
onSelect={(option) => { onSelect={(option) => {
// @ts-ignore TODO(questions): handle potentially null value.
onOptionChange({ onOptionChange({
...option, ...option,
checked: true, checked: true,

@ -29,17 +29,25 @@ type Props = Readonly<{
isLabelHidden?: boolean; isLabelHidden?: boolean;
label: string; label: string;
noResultsMessage?: string; noResultsMessage?: string;
nullable?: boolean;
onQueryChange: ( onQueryChange: (
value: string, value: string,
event: React.ChangeEvent<HTMLInputElement>, event: React.ChangeEvent<HTMLInputElement>,
) => void; ) => void;
onSelect: (option: TypeaheadOption | null) => void;
options: ReadonlyArray<TypeaheadOption>; options: ReadonlyArray<TypeaheadOption>;
textSize?: TypeaheadTextSize; textSize?: TypeaheadTextSize;
value?: TypeaheadOption | null; value?: TypeaheadOption | null;
}> & }> &
Readonly<Attributes>; Readonly<Attributes> &
(
| {
nullable: true;
onSelect: (option: TypeaheadOption | null) => void;
}
| {
nullable?: false;
onSelect: (option: TypeaheadOption) => void;
}
);
type State = 'error' | 'normal'; type State = 'error' | 'normal';

Loading…
Cancel
Save