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() {
60
60
type : "paragraph" ,
61
61
content : "Select some text to try them out" ,
62
62
} ,
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
+ } ,
63
68
{
64
69
type : "paragraph" ,
65
70
} ,
Original file line number Diff line number Diff line change 3
3
useBlockNoteEditor ,
4
4
useComponentsContext ,
5
5
useEditorContentOrSelectionChange ,
6
+ useSelectedBlocks ,
6
7
} from "@blocknote/react" ;
7
8
import { useState } from "react" ;
8
9
@@ -26,6 +27,14 @@ export function BlueButton() {
26
27
) ;
27
28
} , editor ) ;
28
29
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
+
29
38
return (
30
39
< Components . FormattingToolbar . Button
31
40
mainTooltip = { "Blue Text & Background" }
You can’t perform that action at this time.
0 commit comments