duoyun-ui
Version:
A lightweight desktop UI component library, implemented using Gem
32 lines (31 loc) • 1.27 kB
JavaScript
import React from 'react';
import { forwardRef, useImperativeHandle, useRef, useLayoutEffect } from 'react';
export * from '../elements/form';
export const DyFormItem = forwardRef(function (props, ref) {
const elementRef = useRef(null);
useImperativeHandle(ref, () => {
return {
focus(...args) {
return elementRef.current.focus(...args);
},
clearInvalidMessage(...args) {
return elementRef.current.clearInvalidMessage(...args);
},
valid(...args) {
return elementRef.current.valid(...args);
},
get data() {
return elementRef.current.data;
},
};
}, []);
// React Bug?
useLayoutEffect(() => {
const element = elementRef.current;
["type", "multiple", "name", "label", "placeholder", "required", "checked", "autofocus", "disabled", "searchable", "clearable", "loading", "invalid", "value", "renderLabel", "rows", "step", "min", "max", "dataList", "options", "adder", "rules"].map(name => {
element[name] = props[name];
});
}, []);
return React.createElement("dy-form-item", { ref: elementRef, ...props });
});
export default DyFormItem;