Skip to content

Commit a14a2d6

Browse files
(Picklist, Lookup): reflect alignment
1 parent 792a256 commit a14a2d6

File tree

2 files changed

+49
-21
lines changed

2 files changed

+49
-21
lines changed

src/scripts/Lookup.tsx

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import React, {
1414
FC,
1515
} from 'react';
1616
import classnames from 'classnames';
17-
import { AutoAlign } from './AutoAlign';
17+
import { AutoAlign, AutoAlignInjectedProps } from './AutoAlign';
1818
import { Button } from './Button';
1919
import { FormElement, FormElementProps } from './FormElement';
2020
import { Icon, IconCategory } from './Icon';
@@ -181,22 +181,31 @@ const LookupSelectedState: FC<LookupSelectedStateProps> = ({
181181
*/
182182
type LookupScopeSelectorContainerProps = {
183183
scopeListboxId: string;
184-
autoAlignContentRef: Ref<HTMLElement | null>;
185184
children: React.ReactNode;
186-
};
185+
} & AutoAlignInjectedProps;
187186

188187
/**
189188
* Container component for scope selector dropdown with AutoAlign
190189
*/
191190
const LookupScopeSelectorContainer: FC<LookupScopeSelectorContainerProps> = ({
192191
scopeListboxId,
193-
autoAlignContentRef,
194192
children,
193+
alignment,
194+
autoAlignContentRef,
195195
}) => {
196+
const [vertAlign, align] = alignment;
197+
const dropdownClassNames = classnames(
198+
'slds-dropdown',
199+
vertAlign ? `slds-dropdown_${vertAlign}` : undefined,
200+
align ? `slds-dropdown_${align}` : undefined,
201+
'slds-dropdown_length-with-icon-7',
202+
'slds-dropdown_fluid'
203+
);
204+
196205
return (
197206
<div
198207
id={scopeListboxId}
199-
className='react-slds-lookup-dropdown slds-dropdown slds-dropdown_length-with-icon-7 slds-dropdown_fluid'
208+
className={dropdownClassNames}
200209
role='listbox'
201210
aria-label='Scope Options'
202211
ref={useMergeRefs([autoAlignContentRef])}
@@ -424,10 +433,10 @@ const LookupScopeSelector: FC<LookupScopeSelectorProps> = ({
424433
alignmentStyle='menu'
425434
portalClassName={portalClassName}
426435
>
427-
{({ autoAlignContentRef }) => (
436+
{(injectedProps) => (
428437
<LookupScopeSelectorContainer
429438
scopeListboxId={scopeListboxId}
430-
autoAlignContentRef={autoAlignContentRef}
439+
{...injectedProps}
431440
>
432441
<ul
433442
className='slds-listbox slds-listbox_vertical'
@@ -668,9 +677,8 @@ type LookupDropdownContainerProps = {
668677
listboxId: string;
669678
loading?: boolean;
670679
dropdownRef: Ref<HTMLDivElement>;
671-
autoAlignContentRef: Ref<HTMLElement | null>;
672680
children: React.ReactNode;
673-
};
681+
} & AutoAlignInjectedProps;
674682

675683
/**
676684
* Container component for dropdown with merged refs
@@ -679,13 +687,25 @@ const LookupDropdownContainer: FC<LookupDropdownContainerProps> = ({
679687
listboxId,
680688
loading,
681689
dropdownRef,
682-
autoAlignContentRef,
683690
children,
691+
alignment,
692+
autoAlignContentRef,
684693
}) => {
694+
const [vertAlign, align] = alignment;
695+
const dropdownClassNames = classnames(
696+
'react-slds-lookup-dropdown-main',
697+
'slds-dropdown',
698+
vertAlign ? `slds-dropdown_${vertAlign}` : undefined,
699+
align ? `slds-dropdown_${align}` : undefined,
700+
'slds-dropdown_length-with-icon-7',
701+
'slds-dropdown_fluid',
702+
'slds-scrollable_none'
703+
);
704+
685705
return (
686706
<div
687707
id={listboxId}
688-
className='react-slds-lookup-dropdown react-slds-lookup-dropdown-main slds-dropdown slds-dropdown_length-with-icon-7 slds-dropdown_fluid slds-scrollable_none'
708+
className={dropdownClassNames}
689709
role='listbox'
690710
aria-label='Search Results'
691711
tabIndex={0}
@@ -748,12 +768,12 @@ const LookupDropdown: FC<LookupDropdownProps> = ({
748768
alignmentStyle='menu'
749769
portalClassName={portalClassName}
750770
>
751-
{({ autoAlignContentRef }) => (
771+
{(injectedProps) => (
752772
<LookupDropdownContainer
753773
listboxId={listboxId}
754774
loading={loading}
755775
dropdownRef={dropdownRef}
756-
autoAlignContentRef={autoAlignContentRef}
776+
{...injectedProps}
757777
>
758778
{listHeader ? (
759779
<ul
@@ -857,7 +877,6 @@ function useInitComponentStyle() {
857877
'.react-slds-lookup-scope-down-icon-container .react-slds-lookup-scope-down-icon',
858878
'{ width: 0.8rem; height: 0.8rem; }',
859879
],
860-
['.react-slds-lookup-dropdown', '{ left: 0; transform: translateX(0); }'],
861880
[
862881
'.react-slds-lookup-dropdown-main',
863882
`{ max-height: ${LIST_PARENT_MAX_HEIGHT}; min-width: 15rem; }`,

src/scripts/Picklist.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import React, {
1515
import classnames from 'classnames';
1616
import { FormElement, FormElementProps } from './FormElement';
1717
import { Icon } from './Icon';
18-
import { AutoAlign } from './AutoAlign';
18+
import { AutoAlign, RectangleAlignment } from './AutoAlign';
1919
import { DropdownMenuProps } from './DropdownMenu';
2020
import { isElInChildren } from './util';
2121
import { ComponentSettingsContext } from './ComponentSettings';
@@ -530,10 +530,19 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
530530
'slds-is-disabled': disabled,
531531
}
532532
);
533-
const dropdownClassNames = classnames(
534-
'slds-dropdown',
535-
'slds-dropdown_length-5',
536-
menuSize ? `slds-dropdown_${menuSize}` : 'slds-dropdown_fluid'
533+
const createDropdownClassNames = useCallback(
534+
(alignment: RectangleAlignment) => {
535+
const [vertAlign, align] = alignment;
536+
537+
return classnames(
538+
'slds-dropdown',
539+
vertAlign ? `slds-dropdown_${vertAlign}` : undefined,
540+
align ? `slds-dropdown_${align}` : undefined,
541+
'slds-dropdown_length-5',
542+
menuSize ? `slds-dropdown_${menuSize}` : 'slds-dropdown_fluid'
543+
);
544+
},
545+
[menuSize]
537546
);
538547

539548
const formElemProps = {
@@ -597,10 +606,10 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
597606
portalClassName={containerClassNames}
598607
size={menuSize}
599608
>
600-
{({ autoAlignContentRef }) => (
609+
{({ alignment, autoAlignContentRef }) => (
601610
<div
602611
id={listboxId}
603-
className={dropdownClassNames}
612+
className={createDropdownClassNames(alignment)}
604613
role='listbox'
605614
aria-label='Options'
606615
tabIndex={0}

0 commit comments

Comments
 (0)