mirror of
https://github.com/facebook/react.git
synced 2026-02-23 20:23:02 +00:00
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:
@@ -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}
|
||||
|
||||
@@ -53,3 +53,7 @@
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.EditableValue {
|
||||
min-width: 1rem;
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
/>
|
||||
:
|
||||
<EditableValue
|
||||
className={styles.EditableValue}
|
||||
initialValue={''}
|
||||
overrideValueFn={handleNewEntryValue}
|
||||
path={[newPropName]}
|
||||
|
||||
@@ -358,7 +358,7 @@ function InspectedElementView({
|
||||
inspectPath={inspectPropsPath}
|
||||
overrideValueFn={overridePropsFn}
|
||||
showWhenEmpty={true}
|
||||
canAddEntries={true}
|
||||
canAddEntries={typeof overridePropsFn === 'function'}
|
||||
/>
|
||||
{type === ElementTypeSuspense ? (
|
||||
<InspectedElementTree
|
||||
|
||||
Reference in New Issue
Block a user