@@ -53,6 +53,13 @@ function toolbarIn(host: HTMLElement): HTMLElement | null {
5353 return host . querySelector < HTMLElement > ( '[data-inline-text-toolbar="true"]' ) ;
5454}
5555
56+ function renderSelected ( html = "hello world" ) {
57+ const { element, session, iframe } = scene ( html ) ;
58+ const { host } = render ( session , iframe ) ;
59+ selectAll ( element ) ;
60+ return { element, host } ;
61+ }
62+
5663describe ( "InlineTextToolbar" , ( ) => {
5764 it ( "stays out of the way until characters are actually selected" , ( ) => {
5865 const { session, iframe } = scene ( "hello world" ) ;
@@ -152,15 +159,26 @@ describe("InlineTextToolbar", () => {
152159 } ) ;
153160
154161 it ( "styles the selected characters when a control is used" , ( ) => {
155- const { element, session, iframe } = scene ( "hello world" ) ;
156- const { host } = render ( session , iframe ) ;
157- selectAll ( element ) ;
162+ const { element, host } = renderSelected ( ) ;
158163
159164 act ( ( ) => host . querySelector < HTMLButtonElement > ( '[aria-label="Bold"]' ) ! . click ( ) ) ;
160165
161166 expect ( element . innerHTML ) . toBe ( '<span style="font-weight: 700">hello world</span>' ) ;
162167 } ) ;
163168
169+ it ( "ignores a click when the selection disappeared before React hid the toolbar" , ( ) => {
170+ const { element, host } = renderSelected ( ) ;
171+ const bold = host . querySelector < HTMLButtonElement > ( '[aria-label="Bold"]' ) ! ;
172+
173+ expect ( ( ) => {
174+ act ( ( ) => {
175+ document . getSelection ( ) ! . removeAllRanges ( ) ;
176+ bold . click ( ) ;
177+ } ) ;
178+ } ) . not . toThrow ( ) ;
179+ expect ( element . innerHTML ) . toBe ( "hello world" ) ;
180+ } ) ;
181+
164182 it ( "reads back the styling it applied, so the control shows the truth" , ( ) => {
165183 const { element, session, iframe } = scene ( '<span style="font-style: italic">words</span>' ) ;
166184 const { host } = render ( session , iframe ) ;
0 commit comments