Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions documentation-site/components/yard/config/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ const TagConfig: TConfig = {
type: PropTypes.Function,
description: `A component rendered at the start of the tag.`,
},
noMargin: {
value: false,
defaultValue: false,
type: PropTypes.Boolean,
description: `Removes the Tag's default margin. Useful when composing tags in a custom layout.`,
},
overrides: {
value: undefined,
type: PropTypes.Custom,
Expand Down
11 changes: 11 additions & 0 deletions documentation-site/examples/tag/no-margin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from "react";
import { Tag } from "baseui/tag";

export default function Example() {
return (
<div style={{ display: "flex" }}>
<Tag noMargin>no margin</Tag>
<Tag noMargin>no margin</Tag>
</div>
);
}
7 changes: 7 additions & 0 deletions documentation-site/pages/components/tag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Disabled from "examples/tag/disabled.tsx";
import NonCloseable from "examples/tag/non-closeable.tsx";
import ClickableNonCloseable from "examples/tag/clickable-non-closeable.tsx";
import CustomColor from "examples/tag/custom-color.tsx";
import NoMargin from "examples/tag/no-margin.tsx";

import { Tag } from "baseui/tag";
import * as TagExports from "baseui/tag";
Expand Down Expand Up @@ -97,6 +98,12 @@ You can change the color of the tag by passing a value to the `kind` prop. Suppo
<CustomColor />
</Example>

Tag has a default margin so that adjacent tags are spaced out automatically. Set `noMargin` to remove it, for example when composing tags in a custom layout or flex container.

<Example title="Tag with no margin" path="tag/no-margin.tsx">
<NoMargin />
</Example>

## Accessibility

- When the tag is closable or clickable and not disabled it gets the role button and is focusable.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "baseui",
"version": "18.1.0",
"version": "18.2.0",
"description": "A React Component library implementing the Base design language",
"keywords": [
"react",
Expand Down
4 changes: 2 additions & 2 deletions src/tag-group/tag-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

return React.cloneElement(child, {
hierarchy,

Check failure on line 38 in src/tag-group/tag-group.tsx

View workflow job for this annotation

GitHub Actions / Build and Type Check

No overload matches this call.
size,
// All tags in tag group are display only
onActionClick: undefined,
Expand All @@ -43,11 +43,11 @@
onClick: undefined,
onKeyDown: undefined,
closeable: false,
// Single Tag has default margin, reset it to 0 in TagGroup
noMargin: true,
overrides: {
Root: {
style: {
// Single Tag has default margin, reset it to 0 in TagGroup
margin: 0,
...(wrap ? { maxWidth: '100%' } : {}), // ensure wrapping works correctly even if Tag itself has a custom maxWidth(Tag has a default maxWidth 128px on Text inside)
...child.props.overrides?.Root?.style,
},
Expand Down
14 changes: 14 additions & 0 deletions src/tag/__tests__/tag.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ describe('Tag', () => {
expect(actionClickMock.mock.calls.length).toBe(1);
});

it('removes default margin when noMargin is set', () => {
const { container } = render(
<Tag noMargin overrides={{ Root: { props: { 'data-testid': 'root' } } }}>
content
</Tag>
);
const root = getByTestId(container, 'root');
const style = getComputedStyle(root);
expect(style.marginTop).toBe('0px');
expect(style.marginBottom).toBe('0px');
expect(style.marginLeft).toBe('0px');
expect(style.marginRight).toBe('0px');
});

it('passes flow check with tag enum', function () {
// https://github.com/uber/baseweb/issues/1910
// eslint-disable-next-line no-unused-vars
Expand Down
9 changes: 5 additions & 4 deletions src/tag/styled-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export const Root = styled<'span', SharedPropsArg>(
$isFocusVisible,
$color,
$size = SIZE.small,
$noMargin,
} = props;
const borderRadius =
$size === SIZE.small || $size === SIZE.xSmall
Expand Down Expand Up @@ -459,10 +460,10 @@ export const Root = styled<'span', SharedPropsArg>(
[SIZE.large]: '40px',
}[$size],
justifyContent: 'space-between',
marginTop: '5px',
marginBottom: '5px',
marginLeft: '5px',
marginRight: '5px',
marginTop: $noMargin ? 0 : '5px',
marginBottom: $noMargin ? 0 : '5px',
marginLeft: $noMargin ? 0 : '5px',
marginRight: $noMargin ? 0 : '5px',
paddingTop: paddingLongitude,
paddingBottom: paddingLongitude,
paddingLeft: paddingMagnitude,
Expand Down
2 changes: 2 additions & 0 deletions src/tag/tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Tag = React.forwardRef<HTMLSpanElement, TagProps>((props, ref) => {
isFocused = false,
isHovered = false,
kind = KIND.gray,
noMargin = false,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onActionClick = (event) => {},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -118,6 +119,7 @@ const Tag = React.forwardRef<HTMLSpanElement, TagProps>((props, ref) => {
$hierarchy: hierarchy,
$isFocusVisible: focusVisible,
$size: size,
$noMargin: noMargin,
};
const titleText = title || getTextFromChildren(children);
const isButton = (clickable || closeable) && !disabled;
Expand Down
3 changes: 3 additions & 0 deletions src/tag/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export type TagProps = {
size?: TagSize;
startEnhancer?: React.ComponentType<{ size?: number | string }>;
contentMaxWidth?: string | null;
/** Removes the Tag's default margin. Useful when composing tags in a custom layout. */
noMargin?: boolean;
};

export type SharedPropsArg = {
Expand All @@ -72,4 +74,5 @@ export type SharedPropsArg = {
$isFocusVisible?: boolean;
$size?: string;
$contentMaxWidth?: string | null;
$noMargin?: boolean;
};
Loading