File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
examples/03-ui-components/02-formatting-toolbar-buttons/src Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ export default function App() {
6060 type : "paragraph" ,
6161 content : "Select some text to try them out" ,
6262 } ,
63+ {
64+ type : "paragraph" ,
65+ content :
66+ "Notice that the button doesn't appear when the image block above is selected, as it has no inline content." ,
67+ } ,
6368 {
6469 type : "paragraph" ,
6570 } ,
Original file line number Diff line number Diff line change 33 useBlockNoteEditor ,
44 useComponentsContext ,
55 useEditorContentOrSelectionChange ,
6+ useSelectedBlocks ,
67} from "@blocknote/react" ;
78import { useState } from "react" ;
89
@@ -26,6 +27,14 @@ export function BlueButton() {
2627 ) ;
2728 } , editor ) ;
2829
30+ // Doesn't render unless a at least one block with inline content is
31+ // selected. You can use a similar pattern of returning `null` to
32+ // conditionally render buttons based on the editor state.
33+ const blocks = useSelectedBlocks ( ) ;
34+ if ( blocks . filter ( ( block ) => block . content !== undefined ) ) {
35+ return null ;
36+ }
37+
2938 return (
3039 < Components . FormattingToolbar . Button
3140 mainTooltip = { "Blue Text & Background" }
You can’t perform that action at this time.
0 commit comments