Fixed forward reference issue caused by new Antd version.

This commit is contained in:
Patrick Fic
2020-07-15 11:12:30 -07:00
parent 09990b1642
commit bdd1f53ff9
3 changed files with 23 additions and 31 deletions

View File

@@ -1,17 +1,14 @@
import { Select, Row, Col, Tag } from "antd"; import { Select, Row, Col, Tag } from "antd";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState, forwardRef } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import CurrencyFormatter from "../../utils/CurrencyFormatter"; import CurrencyFormatter from "../../utils/CurrencyFormatter";
//To be used as a form element only. //To be used as a form element only.
const { Option } = Select; const { Option } = Select;
const InvoiceLineSearchSelect = ({ const InvoiceLineSearchSelect = (
value, { value, onChange, options, onBlur, onSelect },
onChange, ref
options, ) => {
onBlur,
onSelect,
}) => {
const [option, setOption] = useState(value); const [option, setOption] = useState(value);
const { t } = useTranslation(); const { t } = useTranslation();
@@ -23,6 +20,7 @@ const InvoiceLineSearchSelect = ({
return ( return (
<Select <Select
ref={ref}
showSearch showSearch
autoFocus autoFocus
value={option} value={option}
@@ -62,4 +60,4 @@ const InvoiceLineSearchSelect = ({
</Select> </Select>
); );
}; };
export default InvoiceLineSearchSelect; export default forwardRef(InvoiceLineSearchSelect);

View File

@@ -1,17 +1,13 @@
import { Select } from "antd"; import { Select } from "antd";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState, forwardRef } from "react";
const { Option } = Select; const { Option } = Select;
//To be used as a form element only. //To be used as a form element only.
const JobSearchSelect = ({ const JobSearchSelect = (
value, { value, onChange, options, onBlur, disabled, loading },
onChange, ref
options, ) => {
onBlur,
disabled,
loading,
}) => {
const [option, setOption] = useState(value); const [option, setOption] = useState(value);
useEffect(() => { useEffect(() => {
@@ -22,6 +18,7 @@ const JobSearchSelect = ({
return ( return (
<Select <Select
ref={ref}
disabled={disabled} disabled={disabled}
showSearch showSearch
autoFocus autoFocus
@@ -31,9 +28,8 @@ const JobSearchSelect = ({
}} }}
loading={loading} loading={loading}
onChange={setOption} onChange={setOption}
optionFilterProp="children" optionFilterProp='children'
onBlur={onBlur} onBlur={onBlur}>
>
{options {options
? options.map((o) => ( ? options.map((o) => (
<Option key={o.id} value={o.id}> <Option key={o.id} value={o.id}>
@@ -48,4 +44,4 @@ const JobSearchSelect = ({
</Select> </Select>
); );
}; };
export default JobSearchSelect; export default forwardRef(JobSearchSelect);

View File

@@ -1,16 +1,13 @@
import { Select, Tag } from "antd"; import { Select, Tag } from "antd";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState, forwardRef } from "react";
const { Option } = Select; const { Option } = Select;
//To be used as a form element only. //To be used as a form element only.
const VendorSearchSelect = ({ const VendorSearchSelect = (
value, { value, onChange, options, onSelect, disabled },
onChange, ref
options, ) => {
onSelect,
disabled,
}) => {
const [option, setOption] = useState(value); const [option, setOption] = useState(value);
useEffect(() => { useEffect(() => {
@@ -21,6 +18,7 @@ const VendorSearchSelect = ({
return ( return (
<Select <Select
ref={ref}
showSearch showSearch
value={option} value={option}
style={{ style={{
@@ -43,4 +41,4 @@ const VendorSearchSelect = ({
</Select> </Select>
); );
}; };
export default VendorSearchSelect; export default forwardRef(VendorSearchSelect);