Skip to content

Commit 88fe329

Browse files
authored
fix(forms): InputGroup toggle button stacking (#1778)
1 parent 5668dba commit 88fe329

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

packages/forms/demo/inputGroup.stories.mdx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { Meta, ArgsTable, Canvas, Story, Markdown } from '@storybook/addon-docs';
2-
import { InputGroup, Input, Field, Label, Hint, Message } from '@zendeskgarden/react-forms';
2+
import {
3+
InputGroup,
4+
Input,
5+
Field,
6+
Label,
7+
Hint,
8+
Message,
9+
VALIDATION
10+
} from '@zendeskgarden/react-forms';
311
import { InputGroupStory } from './stories/InputGroupStory';
412
import { INPUT_GROUP_ITEMS as ITEMS } from './stories/data';
513
import { commonArgs, commonArgTypes } from './stories/common';
@@ -32,7 +40,14 @@ import README from '../README.md';
3240
isNeutral: { table: { category: 'Button' } },
3341
isPrimary: { control: 'boolean', table: { category: 'Button' } },
3442
isDanger: { control: 'boolean', table: { category: 'Button' } },
35-
readOnly: { control: 'boolean', table: { category: 'Input' } }
43+
isToggle: { control: 'boolean', name: 'ToggleButton', table: { category: 'Button' } },
44+
readOnly: { control: 'boolean', table: { category: 'Input' } },
45+
inputValidation: {
46+
control: 'radio',
47+
name: 'validation',
48+
options: VALIDATION,
49+
table: { category: 'Input' }
50+
}
3651
}}
3752
parameters={{
3853
design: {

packages/forms/demo/stories/InputGroupStory.tsx

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,49 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import React from 'react';
9-
import { Story } from '@storybook/react';
10-
import { IInputGroupProps, Input, InputGroup } from '@zendeskgarden/react-forms';
8+
import React, { PropsWithChildren, useState } from 'react';
9+
import { StoryFn } from '@storybook/react';
10+
import { IInputGroupProps, IInputProps, Input, InputGroup } from '@zendeskgarden/react-forms';
1111
import { FieldStory, IFieldArgs } from './FieldStory';
1212
import { IInputGroupItem } from './types';
13-
import { Button } from '@zendeskgarden/react-buttons';
13+
import { Button, IButtonProps, ToggleButton } from '@zendeskgarden/react-buttons';
14+
15+
interface IGroupButtonProps extends PropsWithChildren {
16+
disabled?: boolean;
17+
isNeutral: boolean;
18+
isPrimary?: boolean;
19+
isDanger?: boolean;
20+
isToggle?: boolean;
21+
size?: IButtonProps['size'];
22+
}
23+
24+
const GroupButton = ({ isToggle, ...props }: IGroupButtonProps) => {
25+
const [isPressed, setIsPressed] = useState(false);
26+
27+
return isToggle ? (
28+
<ToggleButton
29+
focusInset
30+
{...props}
31+
isPressed={isPressed}
32+
onClick={() => setIsPressed(!isPressed)}
33+
/>
34+
) : (
35+
<Button focusInset {...props} />
36+
);
37+
};
1438

1539
interface IArgs extends IInputGroupProps, IFieldArgs {
1640
items: IInputGroupItem[];
1741
disabled?: boolean;
1842
isNeutral: boolean;
1943
isPrimary?: boolean;
2044
isDanger?: boolean;
45+
isToggle?: boolean;
2146
readOnly?: boolean;
47+
inputValidation?: IInputProps['validation'];
2248
}
2349

24-
export const InputGroupStory: Story<IArgs> = ({
50+
export const InputGroupStory: StoryFn<IArgs> = ({
2551
label,
2652
isLabelRegular,
2753
isLabelHidden,
@@ -35,7 +61,9 @@ export const InputGroupStory: Story<IArgs> = ({
3561
isNeutral,
3662
isPrimary,
3763
isDanger,
64+
isToggle,
3865
readOnly,
66+
inputValidation,
3967
...args
4068
}) => (
4169
<FieldStory
@@ -52,24 +80,25 @@ export const InputGroupStory: Story<IArgs> = ({
5280
<InputGroup {...args}>
5381
{items.map((item, index) =>
5482
item.isButton ? (
55-
<Button
83+
<GroupButton
5684
key={index}
57-
focusInset
5885
disabled={disabled}
5986
isNeutral={isNeutral}
6087
isPrimary={isPrimary}
6188
isDanger={isDanger}
89+
isToggle={isToggle}
6290
size={args.isCompact ? 'small' : undefined}
6391
>
6492
{item.text}
65-
</Button>
93+
</GroupButton>
6694
) : (
6795
<Input
6896
key={index}
6997
placeholder={item.text}
7098
readOnly={readOnly}
7199
disabled={disabled}
72100
isCompact={args.isCompact}
101+
validation={inputValidation}
73102
/>
74103
)
75104
)}

packages/forms/src/styled/input-group/StyledInputGroup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ const itemStyles = (props: ThemeProps<DefaultTheme>) => {
7878
& > ${StyledTextInput}[data-garden-focus-visible],
7979
& > button[data-garden-focus-visible],
8080
& > ${StyledTextInput}:active,
81-
& > button:active {
81+
& > button:active,
82+
& > button[aria-pressed='true'],
83+
& > button[aria-pressed='mixed'] {
8284
z-index: 1;
8385
}
8486

0 commit comments

Comments
 (0)