Skip to content

Commit

Permalink
Fix - Native Select / Select - Additional Content redundancy / CSS (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-cedrone-cengage authored Nov 30, 2023
1 parent bd95074 commit 5e438ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/fix-additionalContent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-dom': minor
---

fix(Select/NativeSelect): Fixed alignment issues in Select regarding additional content icon. Fixed duplicate additional content in Native Select.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ export const NativeSelect = React.forwardRef<HTMLDivElement, NativeSelectProps>(
return props.children;
}

function inlineContent() {
if (!labelText || labelPosition !== LabelPosition.top) {
return additionalContent;
}
}

return (
<AdditionalContentWrapper labelPosition={labelPosition}>
<StyledFormFieldContainer
Expand Down Expand Up @@ -207,7 +201,8 @@ export const NativeSelect = React.forwardRef<HTMLDivElement, NativeSelectProps>(
<DefaultDropdownIndicator disabled={disabled} />
</StyledNativeSelectWrapper>
</StyledFormFieldContainer>
{inlineContent()}
{(labelPosition === 'left' && additionalContent) ||
(!labelText && additionalContent)}
</AdditionalContentWrapper>
);
}
Expand Down
31 changes: 25 additions & 6 deletions packages/react-magma-dom/src/components/Select/SelectContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,37 @@ interface SelectContainerInterface<T> {
messageStyle?: React.CSSProperties;
}

const StyledAdditionalContentWrapper = styled.div<{ theme?: ThemeInterface }>`
const StyledAdditionalContentWrapper = styled.div<{
labelPosition?: LabelPosition;
theme?: ThemeInterface;
}>`
align-items: center;
display: flex;
flex: 1;
justify-content: space-between;
label {
margin: 0 ${props => props.theme.spaceScale.spacing03} 0 0;
margin: ${props =>
props.labelPosition === LabelPosition.left
? `0 ${props.theme.spaceScale.spacing03} 0 0`
: ''};
}
button {
bottom: ${props =>
props.labelPosition !== LabelPosition.left ? `6px` : ''};
}
`;

const StyledAdditionalContent = styled.div<{ theme?: ThemeInterface }>`
const StyledAdditionalContent = styled.div<{
labelPosition?: LabelPosition;
theme?: ThemeInterface;
}>`
display: flex;
align-items: center;
button {
margin: 0 0 0 ${props => props.theme.spaceScale.spacing03};
margin: ${props =>
props.labelPosition === LabelPosition.left
? `0 0 0 ${props.theme.spaceScale.spacing03}`
: ''};
}
`;

Expand Down Expand Up @@ -95,7 +111,10 @@ export function SelectContainer<T>(props: SelectContainerInterface<T>) {
additionalContent
) {
return (
<StyledAdditionalContentWrapper theme={theme}>
<StyledAdditionalContentWrapper
labelPosition={labelPosition}
theme={theme}
>
{props.children}
{additionalContent}
</StyledAdditionalContentWrapper>
Expand All @@ -111,7 +130,7 @@ export function SelectContainer<T>(props: SelectContainerInterface<T>) {
(labelPosition && isLabelVisuallyHidden && additionalContent)
) {
return (
<StyledAdditionalContent theme={theme}>
<StyledAdditionalContent labelPosition={labelPosition} theme={theme}>
{additionalContent}
</StyledAdditionalContent>
);
Expand Down

2 comments on commit 5e438ab

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.