Skip to content

Commit

Permalink
[components, form-builder] fix child presence on collapsed objects an…
Browse files Browse the repository at this point in the history
…d fieldsets
  • Loading branch information
vicmeow authored and skogsmaskin committed Oct 22, 2020
1 parent bb35633 commit 78b3c49
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/@sanity/components/src/fieldsets/DefaultFieldset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ export default class Fieldset extends React.PureComponent<FieldsetProps, State>
const showSummary = isCollapsible && isCollapsed
// Hide the tooltip if field is collapsible, but field is not collapsed
const hideTooltip = isCollapsible && !isCollapsed
const childPresence = isCollapsible && isCollapsed ? presence : []
return (
<div
{...rest}
onFocus={this.handleFocus}
tabIndex={tabIndex}
tabIndex={isCollapsible && isCollapsed ? tabIndex : -1}
ref={this.setFocusElement}
className={rootClassName}
>
Expand Down Expand Up @@ -192,9 +193,11 @@ export default class Fieldset extends React.PureComponent<FieldsetProps, State>
</p>
)}
</div>
<FieldStatus>
<FieldPresence maxAvatars={4} presence={presence} />
</FieldStatus>
{isCollapsible && (
<FieldStatus>
<FieldPresence maxAvatars={4} presence={childPresence} />
</FieldStatus>
)}
</div>

{isCollapsible && !isCollapsed && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class ObjectInput extends React.PureComponent<ObjectInputProps> {
columns={columns}
isCollapsible={collapsibleOpts.collapsible}
isCollapsed={isCollapsed}
presence={isCollapsed ? childPresence : []}
presence={childPresence}
onFocus={onFocus}
changeIndicator={false}
markers={markers}
Expand Down Expand Up @@ -243,7 +243,7 @@ export default class ObjectInput extends React.PureComponent<ObjectInputProps> {
isCollapsible={collapsibleOpts.collapsible}
isCollapsed={isCollapsed}
markers={markers}
presence={presence.filter(item => item.path[0] === '$' || item.path.length === 0)}
presence={presence}
onFocus={onFocus}
changeIndicator={false}
>
Expand Down
17 changes: 16 additions & 1 deletion packages/test-studio/schemas/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,22 @@ export default {
'This is a field of (anonymous, inline) object type. Values here should never get a `_type` property',
fields: [
{name: 'field1', type: 'string', description: 'This is a string field'},
{name: 'field2', type: 'string', description: 'This is a collapsed field'}
{name: 'field2', type: 'string', description: 'This is a collapsed field'},
{
name: 'field3',
type: 'object',
options: {collapsible: true, collapsed: true},
fields: [
{name: 'nested1', title: 'nested1', type: 'string'},
{
name: 'nested2',
title: 'nested2',
type: 'object',
fields: [{name: 'ge', title: 'hello', type: 'string'}],
options: {collapsible: true, collapsed: true}
}
]
}
]
},
{
Expand Down

1 comment on commit 78b3c49

@vercel
Copy link

@vercel vercel bot commented on 78b3c49 Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.