DevTools: Props editing interface tweaks (#16740)

* Fix DevTools new prop input size
* Don't allow adding new values unless an overridePropsFn function has been provided.
* Do not show empty 'none' label ablve a new prop input
This commit is contained in:
Brian Vaughn
2019-09-10 14:57:33 -07:00
committed by GitHub
parent 2ce5801c25
commit 2c98af77c3
4 changed files with 10 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ import {useEditableValue} from '../hooks';
type OverrideValueFn = (path: Array<string | number>, value: any) => void;
type EditableValueProps = {|
className?: string,
dataType: string,
initialValue: any,
overrideValueFn: OverrideValueFn,
@@ -23,6 +24,7 @@ type EditableValueProps = {|
|};
export default function EditableValue({
className = '',
dataType,
initialValue,
overrideValueFn,
@@ -74,7 +76,7 @@ export default function EditableValue({
<Fragment>
<input
autoComplete="new-password"
className={isValid ? styles.Input : styles.Invalid}
className={`${isValid ? styles.Input : styles.Invalid} ${className}`}
onChange={handleChange}
onKeyDown={handleKeyDown}
placeholder={placeholder}

View File

@@ -53,3 +53,7 @@
display: flex;
align-items: center;
}
.EditableValue {
min-width: 1rem;
}

View File

@@ -82,7 +82,7 @@ export default function InspectedElementTree({
</Button>
)}
</div>
{isEmpty && <div className={styles.Empty}>None</div>}
{isEmpty && !canAddEntries && <div className={styles.Empty}>None</div>}
{!isEmpty &&
(entries: any).map(([name, value]) => (
<KeyValue
@@ -104,6 +104,7 @@ export default function InspectedElementTree({
/>
:&nbsp;
<EditableValue
className={styles.EditableValue}
initialValue={''}
overrideValueFn={handleNewEntryValue}
path={[newPropName]}

View File

@@ -358,7 +358,7 @@ function InspectedElementView({
inspectPath={inspectPropsPath}
overrideValueFn={overridePropsFn}
showWhenEmpty={true}
canAddEntries={true}
canAddEntries={typeof overridePropsFn === 'function'}
/>
{type === ElementTypeSuspense ? (
<InspectedElementTree