-
Notifications
You must be signed in to change notification settings - Fork 3
Add anchorMode prop with left and caret options
#89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import React, { useState } from 'react' | ||
|
|
||
| import { Mention, MentionsInput } from '../../../src' | ||
| import type { MentionDataItem, MentionsInputChangeEvent } from '../../../src' | ||
| import ExampleCard from './ExampleCard' | ||
|
|
||
| export default function LeftAnchored({ data }: { data: MentionDataItem[] }) { | ||
| const [value, setValue] = useState('') | ||
|
|
||
| const onMentionsChange = ({ value: nextValue }: MentionsInputChangeEvent) => { | ||
| setValue(nextValue) | ||
| } | ||
|
|
||
| return ( | ||
| <ExampleCard | ||
| title="Left anchored suggestions" | ||
| description="Pop the overlay from the input edge instead of the caret, ideal for wide inputs." | ||
| > | ||
| <MentionsInput | ||
| anchorMode="left" | ||
| value={value} | ||
| onMentionsChange={onMentionsChange} | ||
| className="mentions" | ||
| placeholder="Start typing '@' to mention" | ||
| a11ySuggestionsListLabel="Suggested mentions" | ||
| > | ||
| <Mention data={data} /> | ||
| </MentionsInput> | ||
| </ExampleCard> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -371,7 +371,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('should load suggestions from async data providers.', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const asyncData = jest.fn(async (query: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await Promise.resolve() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: 'async-one', display: 'Async One' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -661,7 +661,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| </MentionsInput> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const computed = window.getComputedStyle(combobox) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderTop = Number.parseFloat(computed.borderTopWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderBottom = Number.parseFloat(computed.borderBottomWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(Number.parseFloat(combobox.style.height)).toBe(scrollHeight + borderTop + borderBottom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -693,7 +693,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| </MentionsInput> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const computed = window.getComputedStyle(combobox) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderTop = Number.parseFloat(computed.borderTopWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderBottom = Number.parseFloat(computed.borderBottomWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(Number.parseFloat(combobox.style.height)).toBe(scrollHeight + borderTop + borderBottom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -740,7 +740,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await waitFor(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const computed = window.getComputedStyle(combobox) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderTop = Number.parseFloat(computed.borderTopWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderBottom = Number.parseFloat(computed.borderBottomWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(Number.parseFloat(combobox.style.height)).toBe( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -765,7 +765,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('adds border widths to the measured height', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const onMentionsChange = jest.fn() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const getComputedStyleSpy = jest.spyOn(window, 'getComputedStyle').mockReturnValue({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| borderTopWidth: '4px', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| borderBottomWidth: '6px', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } as unknown as CSSStyleDeclaration) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -824,7 +824,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| </MentionsInput> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const computed = window.getComputedStyle(textarea) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderTop = Number.parseFloat(computed.borderTopWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const borderBottom = Number.parseFloat(computed.borderBottomWidth || '0') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(Number.parseFloat(textarea.style.height)).toBe(scrollHeight + borderTop + borderBottom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1396,7 +1396,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| const textarea = screen.getByRole('combobox') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fireEvent.focus(textarea) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const initialIndex = textarea.value.indexOf('First') + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(initialIndex).toBeGreaterThan(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| textarea.setSelectionRange(initialIndex, initialIndex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fireEvent.select(textarea) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1412,7 +1412,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| </MentionsInput> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const updatedIndex = textarea.value.indexOf('Second') + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(updatedIndex).toBeGreaterThan(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| textarea.setSelectionRange(updatedIndex, updatedIndex) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fireEvent.select(textarea) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1851,7 +1851,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| const suggestions = document.createElement('div') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const container = document.createElement('div') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.style.fontSize = '18px' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| suggestions.style.marginLeft = '5px' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| suggestions.style.marginLeft = '0px' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| suggestions.style.marginTop = '7px' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(highlighter, 'getBoundingClientRect', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1871,6 +1871,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.highlighterElement = highlighter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.suggestionsElement = suggestions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.containerElement = container | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.scrollLeft = 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.scrollTop = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(highlighter, 'offsetWidth', { value: 200, configurable: true }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(container, 'offsetWidth', { value: 320, configurable: true }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setStateMock = jest.spyOn(instance, 'setState').mockImplementation((update, cb) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nextState = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1887,9 +1891,92 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(instance.state.suggestionsPosition.position).toBe('fixed') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(typeof instance.state.suggestionsPosition.left).toBe('number') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(instance.state.suggestionsPosition.left).toBe(9) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(typeof instance.state.suggestionsPosition.top).toBe('number') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| act(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.state.suggestionsPosition = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.assign(instance.props, { anchorMode: 'left' }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| act(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.updateSuggestionsPosition() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(instance.state.suggestionsPosition.position).toBe('fixed') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(instance.state.suggestionsPosition.left).toBe(4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.remove() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| suggestions.remove() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| container.remove() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setStateMock.mockRestore() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unmount() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('anchors suggestions to the control edge when using anchorMode="left" outside portals.', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ref = React.createRef<MentionsInput>() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { unmount } = render( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <MentionsInput ref={ref} value="" anchorMode="left"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Mention trigger="@" data={data} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </MentionsInput> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await waitFor(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(ref.current).not.toBeNull() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const instance = ref.current as unknown as any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(instance, 'resolvePortalHost', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: () => null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| configurable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| writable: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const highlighter = document.createElement('div') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const suggestions = document.createElement('div') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const container = document.createElement('div') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.style.fontSize = '16px' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(highlighter, 'getBoundingClientRect', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| left: 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| top: 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| right: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bottom: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| height: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(highlighter, 'offsetWidth', { value: 180, configurable: true }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(container, 'offsetWidth', { value: 220, configurable: true }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.defineProperty(suggestions, 'offsetHeight', { value: 40, configurable: true }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| document.body.append(highlighter) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| document.body.append(suggestions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| document.body.append(container) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.scrollLeft = 14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.scrollTop = 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.highlighterElement = highlighter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.suggestionsElement = suggestions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.containerElement = container | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.state.caretPosition = { left: 32, top: 18 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.state.suggestionsPosition = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setStateMock = jest.spyOn(instance, 'setState').mockImplementation((update, cb) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const nextState = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| typeof update === 'function' ? update(instance.state, instance.props) : update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.assign(instance.state, nextState) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cb?.() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| act(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| instance.updateSuggestionsPosition() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(instance.state.suggestionsPosition.position).toBeUndefined() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(instance.state.suggestionsPosition.left).toBe(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(instance.state.suggestionsPosition.right).toBeUndefined() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| highlighter.remove() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| suggestions.remove() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| container.remove() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1941,6 +2028,21 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;(globalThis as any).ResizeObserver = MockResizeObserver | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const originalAdd = window.addEventListener | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const originalRemove = window.removeEventListener | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handlers: Partial<Record<string, EventListener>> = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const addListener = jest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .spyOn(window, 'addEventListener') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .mockImplementation((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 2036 in src/MentionsInput.spec.tsx
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handlers[type] = listener as EventListener | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return originalAdd.call(window, type, listener, options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const removeListener = jest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .spyOn(window, 'removeEventListener') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .mockImplementation((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return originalRemove.call(window, type, listener, options) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const bridgeElement = instance.renderMeasurementBridge() as React.ReactElement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { unmount: unmountBridge } = render(bridgeElement) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1957,10 +2059,32 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(syncScroll.mock.calls.length).toBe(syncCalls + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(updatePosition.mock.calls.length).toBe(positionCalls + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| act(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.dispatchEvent(new Event('resize')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(syncScroll.mock.calls.length).toBeGreaterThan(syncCalls + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(updatePosition.mock.calls.length).toBeGreaterThan(positionCalls + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| act(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.dispatchEvent(new Event('orientationchange')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(syncScroll.mock.calls.length).toBeGreaterThan(syncCalls + 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(updatePosition.mock.calls.length).toBeGreaterThan(positionCalls + 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
2062
to
2074
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider using While act(() => {
- window.dispatchEvent(new Event('resize'))
+ globalThis.dispatchEvent(new Event('resize'))
})
expect(syncScroll.mock.calls.length).toBeGreaterThan(syncCalls + 1)
expect(updatePosition.mock.calls.length).toBeGreaterThan(positionCalls + 1)
act(() => {
- window.dispatchEvent(new Event('orientationchange'))
+ globalThis.dispatchEvent(new Event('orientationchange'))
})📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unmountBridge() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const observer of observers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(observer.disconnect).toHaveBeenCalled() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(handlers.resize).toBeDefined() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(handlers.orientationchange).toBeDefined() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(addListener).toHaveBeenCalledWith('resize', handlers.resize) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(addListener).toHaveBeenCalledWith('orientationchange', handlers.orientationchange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(removeListener).toHaveBeenCalledWith('resize', handlers.resize) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(removeListener).toHaveBeenCalledWith('orientationchange', handlers.orientationchange) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| addListener.mockRestore() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| removeListener.mockRestore() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;(globalThis as any).ResizeObserver = originalResizeObserver | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unmount() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix linting and formatting issues.
Static analysis has flagged two issues:
globalThisoverwindow(ESLint)Apply this diff to address both issues:
📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: build
[failure] 2036-2036:
Replace
(type:·string,·listener:·EventListenerOrEventListenerObject,·options?:·boolean·|·AddEventListenerOptionswith⏎··········(⏎············type:·string,⏎············listener:·EventListenerOrEventListenerObject,⏎············options?:·boolean·|·AddEventListenerOptions⏎··········[failure] 2035-2035:
Prefer
globalThisoverwindow🤖 Prompt for AI Agents