Skip to content

Commit

Permalink
LPS-139246 - Provide initial values and pass proper event to onChange
Browse files Browse the repository at this point in the history
  • Loading branch information
bryceosterhaus committed Sep 23, 2021
1 parent a542760 commit ab3094c
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function ObjectRelationship({
apiURL,
inputName,
labelKey = 'label',
initialLabel,
initialValue,
name,
onBlur = () => {},
onChange,
Expand Down Expand Up @@ -73,7 +75,7 @@ export function ObjectRelationship({

const loading = networkStatus < NETWORK_STATUS_UNUSED;

value = mutatedRef.current ? value : predefinedValue;
value = mutatedRef.current ? value : initialValue || predefinedValue;

return (
<FieldBase
Expand All @@ -89,14 +91,14 @@ export function ObjectRelationship({
onChange={(event) => {
mutatedRef.current = true;

onChange(event.target.value);
onChange(event, event.target.value);
}}
onBlur={onBlur}
onFocus={onFocus}
placeholder={placeholder}
readOnly={readOnly}
required={required}
value={value}
value={mutatedRef.current ? value : initialLabel}
/>

<ClayAutocomplete.DropDown
Expand All @@ -118,8 +120,11 @@ export function ObjectRelationship({
<ClayAutocomplete.Item
key={item.id}
match={String(value)}
onClick={() =>
onChange(String(item[valueKey]))
onClick={(event) =>
onChange(
event,
String(item[valueKey])
)
}
value={String(item[labelKey])}
/>
Expand Down

0 comments on commit ab3094c

Please sign in to comment.