How to click the button to bold the selected text?

I want to click a button after selecting the text of the contenteditable element on the page, and use the document.execCommand () method to bold the selected text, but when I click this button, the input box will blur and the corresponding text will not be obtained. how to solve the focus problem in this case?

Jun.21,2022

you can refer to this example

Menu