Skip to content

Commit

Permalink
Use Colors: Allow specifying a query selector for the background colo…
Browse files Browse the repository at this point in the history
…r detector to start searching from.
  • Loading branch information
epiqueras committed Nov 4, 2019
1 parent 62392a3 commit f99d9be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/colors/use-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ export default function __experimentalUseColors(
const detectedBackgroundColorRef = useRef();
const BackgroundColorDetector = useMemo(
() =>
withFallbackStyles( ( node ) => {
withFallbackStyles( ( node, { querySelector } ) => {
if ( querySelector ) {
node = node.parentNode.querySelector( querySelector );
}
let backgroundColor = getComputedStyle( node ).backgroundColor;
while ( backgroundColor === 'rgba(0, 0, 0, 0)' && node.parentNode ) {
node = node.parentNode;
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function HeadingEdit( {
</PanelBody>
</InspectorControls>
{ InspectorControlsColorPanel }
<BackgroundColorDetector />
<TextColor>
<BackgroundColorDetector querySelector='[contenteditable="true"]' />
<RichText
identifier="content"
tagName={ tagName }
Expand Down

0 comments on commit f99d9be

Please sign in to comment.