Skip to content

Commit

Permalink
Capture element selections (#4338)
Browse files Browse the repository at this point in the history
  • Loading branch information
samarsault committed Jul 6, 2021
1 parent 51bfb40 commit d3d6c51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
6 changes: 1 addition & 5 deletions packages/slate-react/src/components/element.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ const Element = (props: {
}
})

return (
<SelectedContext.Provider value={!!selection}>
{renderElement({ attributes, children, element })}
</SelectedContext.Provider>
)
return renderElement({ attributes, children, element })
}

const MemoizedElement = React.memo(Element, (prev, next) => {
Expand Down
21 changes: 12 additions & 9 deletions packages/slate-react/src/hooks/use-children.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
RenderLeafProps,
RenderPlaceholderProps,
} from '../components/editable'
import { SelectedContext } from './use-selected'

/**
* Children.
Expand Down Expand Up @@ -60,15 +61,17 @@ const useChildren = (props: {

if (Element.isElement(n)) {
children.push(
<ElementComponent
decorations={ds}
element={n}
key={key.id}
renderElement={renderElement}
renderPlaceholder={renderPlaceholder}
renderLeaf={renderLeaf}
selection={sel}
/>
<SelectedContext.Provider value={!!sel}>
<ElementComponent
decorations={ds}
element={n}
key={key.id}
renderElement={renderElement}
renderPlaceholder={renderPlaceholder}
renderLeaf={renderLeaf}
selection={sel}
/>
</SelectedContext.Provider>
)
} else {
children.push(
Expand Down

0 comments on commit d3d6c51

Please sign in to comment.