-
Notifications
You must be signed in to change notification settings - Fork 15
feat(menu)!: allow users to specify both window and document env #694
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,25 +39,32 @@ import { | |||||||||||||||||||
| } from './types'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const useMenu = <T extends HTMLElement = HTMLElement, M extends HTMLElement = HTMLElement>({ | ||||||||||||||||||||
| items: rawItems, | ||||||||||||||||||||
| idPrefix, | ||||||||||||||||||||
| defaultExpanded = false, | ||||||||||||||||||||
| defaultFocusedValue, | ||||||||||||||||||||
| document: documentProp, | ||||||||||||||||||||
| environment, | ||||||||||||||||||||
| menuRef, | ||||||||||||||||||||
| triggerRef, | ||||||||||||||||||||
| rtl = false, | ||||||||||||||||||||
| onChange = () => undefined, | ||||||||||||||||||||
| focusedValue, | ||||||||||||||||||||
| idPrefix, | ||||||||||||||||||||
| isExpanded, | ||||||||||||||||||||
| defaultExpanded = false, | ||||||||||||||||||||
| items: rawItems, | ||||||||||||||||||||
| menuRef, | ||||||||||||||||||||
| restoreFocus = true, | ||||||||||||||||||||
| rtl = false, | ||||||||||||||||||||
| selectedItems, | ||||||||||||||||||||
| focusedValue, | ||||||||||||||||||||
| defaultFocusedValue | ||||||||||||||||||||
| triggerRef, | ||||||||||||||||||||
| window: windowProp, | ||||||||||||||||||||
| onChange = () => undefined | ||||||||||||||||||||
| }: IUseMenuProps<T, M>): IUseMenuReturnValue => { | ||||||||||||||||||||
| const prefix = `${useId(idPrefix)}-`; | ||||||||||||||||||||
| const triggerId = `${prefix}menu-trigger`; | ||||||||||||||||||||
| const isExpandedControlled = isExpanded !== undefined; | ||||||||||||||||||||
| const isSelectedItemsControlled = selectedItems !== undefined; | ||||||||||||||||||||
| const isFocusedValueControlled = focusedValue !== undefined; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const _window = windowProp || environment; | ||||||||||||||||||||
|
||||||||||||||||||||
| let _document: Document | ShadowRoot = _window ? _window.document : window.document; | ||||||||||||||||||||
| _document = documentProp ? documentProp : _document; | ||||||||||||||||||||
|
||||||||||||||||||||
| let _document: Document | ShadowRoot = _window ? _window.document : window.document; | |
| _document = documentProp ? documentProp : _document; | |
| let _document: IUseMenuProps['document']; | |
| if (documentProp) { | |
| _document = documentProp | |
| } else { | |
| _document = _window ? _window.document : window.document; | |
| } |
...for improved readability and type reuse. Repeated ternaries are difficult to read and usually a signal for refactor.
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.
Let's not deprecate; prefer the immediate
feat(menu)!: ...breaking change inreact-containers