Skip to content

Commit

Permalink
fix: sonar
Browse files Browse the repository at this point in the history
sonar
  • Loading branch information
815are committed Oct 24, 2024
1 parent c1483b4 commit aa34291
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class UIComboBox extends React.Component<UIComboBoxProps, UIComboBoxState
private query = '';
private ignoreOpenKeys: Array<string> = ['Meta', 'Control', 'Shift', 'Tab', 'Alt', 'CapsLock'];
private isListHidden = false;
public readonly calloutCollisionTransform = new CalloutCollisionTransform(this.comboboxDomRef, this.menuDomRef);
private calloutCollisionTransform = new CalloutCollisionTransform(this.comboboxDomRef, this.menuDomRef);

/**
* Initializes component properties.
Expand Down Expand Up @@ -764,7 +764,7 @@ export class UIComboBox extends React.Component<UIComboBoxProps, UIComboBoxState
},

...this.props.calloutProps,
...getCalloutCollisionTransformationPropsForDropdown(this)
...getCalloutCollisionTransformationPropsForDropdown(this, this.calloutCollisionTransform)
}}
{...(this.props.highlight && {
onInput: this.onInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ERROR_BORDER_COLOR = 'var(--vscode-inputValidation-errorBorder)';
export class UIDropdown extends React.Component<UIDropdownProps, UIDropdownState> {
private dropdownDomRef = React.createRef<HTMLDivElement>();
private menuDomRef = React.createRef<HTMLDivElement>();
public readonly calloutCollisionTransform = new CalloutCollisionTransform(this.dropdownDomRef, this.menuDomRef);
private calloutCollisionTransform = new CalloutCollisionTransform(this.dropdownDomRef, this.menuDomRef);

/**
* Initializes component properties.
Expand Down Expand Up @@ -330,7 +330,7 @@ export class UIDropdown extends React.Component<UIDropdownProps, UIDropdownState
ref: this.menuDomRef
},
...this.props.calloutProps,
...getCalloutCollisionTransformationPropsForDropdown(this)
...getCalloutCollisionTransformationPropsForDropdown(this, this.calloutCollisionTransform)
}}
onRenderOption={this.onRenderOption.bind(this)}
onRenderItem={this.onRenderItem.bind(this)}
Expand Down
32 changes: 22 additions & 10 deletions packages/ui-components/src/components/UIDropdown/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ export function getCalloutCollisionTransformationProps(
* Method returns callback function to 'onLayerDidMount' property of dropdown 'callout'.
*
* @param dropdown Instance of dropdown.
* @param calloutCollisionTransform of callout collision transformation.
* @returns Returns callback function to 'onLayerDidMount' property of dropdown 'callout'.
*/
function getOnLayerDidMount(dropdown: UIDropdown | UIComboBox): () => void {
function getOnLayerDidMount(
dropdown: UIDropdown | UIComboBox,
calloutCollisionTransform: CalloutCollisionTransform
): () => void {
return () => {
const { layerProps } =
getCalloutCollisionTransformationProps(
dropdown.calloutCollisionTransform,
calloutCollisionTransform,
dropdown.props.multiSelect,
dropdown.props.calloutCollisionTransformation
) ?? {};
Expand All @@ -74,13 +78,17 @@ function getOnLayerDidMount(dropdown: UIDropdown | UIComboBox): () => void {
* Method returns callback function to 'onLayerWillUnmount' property of dropdown 'callout'.
*
* @param dropdown Instance of dropdown.
* @param calloutCollisionTransform of callout collision transformation.
* @returns Returns callback function to 'onLayerWillUnmount' property of dropdown 'callout'.
*/
function getOnLayerWillUnmount(dropdown: UIDropdown | UIComboBox): () => void {
function getOnLayerWillUnmount(
dropdown: UIDropdown | UIComboBox,
calloutCollisionTransform: CalloutCollisionTransform
): () => void {
return () => {
const { layerProps } =
getCalloutCollisionTransformationProps(
dropdown.calloutCollisionTransform,
calloutCollisionTransform,
dropdown.props.multiSelect,
dropdown.props.calloutCollisionTransformation
) ?? {};
Expand All @@ -97,10 +105,12 @@ function getOnLayerWillUnmount(dropdown: UIDropdown | UIComboBox): () => void {
* Method returns callback function to 'preventDismissOnEvent' property of dropdown 'callout', which prevents callout dismiss/close if focus/click on target elements.
*
* @param dropdown Instance of dropdown.
* @param calloutCollisionTransform of callout collision transformation.
* @returns Returns callback function to 'preventDismissOnEvent' property of dropdown 'callout'.
*/
function getPreventDismissOnEvent(
dropdown: UIDropdown | UIComboBox
dropdown: UIDropdown | UIComboBox,
calloutCollisionTransform: CalloutCollisionTransform
): (
event: Event | React.FocusEvent<Element> | React.KeyboardEvent<Element> | React.MouseEvent<Element, MouseEvent>
) => boolean {
Expand All @@ -112,7 +122,7 @@ function getPreventDismissOnEvent(
if (!preventDismiss) {
const { preventDismissOnEvent } =
getCalloutCollisionTransformationProps(
dropdown.calloutCollisionTransform,
calloutCollisionTransform,
dropdown.props.multiSelect,
dropdown.props.calloutCollisionTransformation
) ?? {};
Expand All @@ -130,17 +140,19 @@ function getPreventDismissOnEvent(
* and if overlap happens, then additional offset is applied to make action buttons visible.
*
* @param dropdown Instance of dropdown.
* @param calloutCollisionTransform of callout collision transformation.
* @returns Callout props to enable callout collision transformation.
*/
export function getCalloutCollisionTransformationPropsForDropdown(
dropdown: UIDropdown | UIComboBox
dropdown: UIDropdown | UIComboBox,
calloutCollisionTransform: CalloutCollisionTransform
): ICalloutProps | undefined {
if (dropdown.props.multiSelect && dropdown.props.calloutCollisionTransformation) {
return {
preventDismissOnEvent: getPreventDismissOnEvent(dropdown),
preventDismissOnEvent: getPreventDismissOnEvent(dropdown, calloutCollisionTransform),
layerProps: {
onLayerDidMount: getOnLayerDidMount(dropdown),
onLayerWillUnmount: getOnLayerWillUnmount(dropdown)
onLayerDidMount: getOnLayerDidMount(dropdown, calloutCollisionTransform),
onLayerWillUnmount: getOnLayerWillUnmount(dropdown, calloutCollisionTransform)
}
};
}
Expand Down

0 comments on commit aa34291

Please sign in to comment.