Allow InputAddress with no options (#4227)
* Allow InputAddress with no options * Update packages/react-params/src/Param/index.tsx
This commit is contained in:
parent
e6a1470d4d
commit
1cf7b5e629
@ -133,14 +133,8 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { className = '', defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, labelExtra, options, optionsAll, placeholder, type = DEFAULT_TYPE, withEllipsis, withLabel } = this.props;
|
||||
const { className = '', defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, labelExtra, options, placeholder, withEllipsis, withLabel } = this.props;
|
||||
const { lastValue, value } = this.state;
|
||||
const hasOptions = (options && options.length !== 0) || (optionsAll && Object.keys(optionsAll[type]).length !== 0);
|
||||
|
||||
if (!hasOptions && !isDisabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const lastOption = this.getLastOptionValue();
|
||||
const actualValue = transformToAddress(
|
||||
isDisabled || (defaultValue && this.hasValue(defaultValue))
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
// Copyright 2017-2020 @polkadot/react-params authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Props as CProps, Props } from '../types';
|
||||
import type { Props } from '../types';
|
||||
|
||||
import React, { useMemo, useRef } from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { encodeTypeDef } from '@polkadot/types/create';
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
@ -12,7 +12,10 @@ import findComponent from './findComponent';
|
||||
import Static from './Static';
|
||||
|
||||
function Param ({ className = '', defaultValue, isDisabled, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> | null {
|
||||
const compRef = useRef<React.ComponentType<CProps> | null>(findComponent(registry, type, overrides));
|
||||
const Component = useMemo(
|
||||
() => findComponent(registry, type, overrides),
|
||||
[registry, type, overrides]
|
||||
);
|
||||
|
||||
const label = useMemo(
|
||||
() => isUndefined(name)
|
||||
@ -21,7 +24,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption
|
||||
[name, type]
|
||||
);
|
||||
|
||||
if (!compRef.current) {
|
||||
if (!Component) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -34,7 +37,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption
|
||||
/>
|
||||
)
|
||||
: (
|
||||
<compRef.current
|
||||
<Component
|
||||
className={`ui--Param ${className}`}
|
||||
defaultValue={defaultValue}
|
||||
isDisabled={isDisabled}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user