Skip to content

Commit 2685c42

Browse files
Merge release/v3.1.1 into main branch (#1233)
1 parent fe4c6ec commit 2685c42

File tree

12 files changed

+130
-27
lines changed

12 files changed

+130
-27
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "yarn" # See documentation for possible values
8+
- package-ecosystem: "npm" # See documentation for possible values
99
directory: "/" # Location of package manifests
1010
schedule:
1111
interval: "weekly"

.github/workflows/chromatic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
steps:
1717
- name: Checkout branch
1818
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # 👈 Required to retrieve git history
1921

2022
- name: Setup Node
2123
uses: actions/setup-node@v4

.github/workflows/gh-pages-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
run: yarn build-storybook
3939

4040
- name: Upload
41-
uses: actions/upload-pages-artifact@v4
41+
uses: actions/upload-pages-artifact@v3
4242
with:
4343
path: "storybook-static"
4444

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@user-interviews/ui-design-system",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"dependencies": {
55
"@tiptap/core": "^2.3.1",
66
"@tiptap/extension-bold": "^2.3.1",

src/Drawer/Drawer.test.tsx

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState } from 'react';
2-
import propTypes from 'prop-types';
32

43
import { render, screen, waitFor } from '@testing-library/react';
54
import userEvent from '@testing-library/user-event';
@@ -26,6 +25,9 @@ const elements = {
2625
drawerThreeToggleVisibilityButton: {
2726
get: () => screen.getByRole('button', { name: /toggle visibility drawerThree/ }),
2827
},
28+
drawerFourToggleVisibilityButton: {
29+
get: () => screen.getByRole('button', { name: /toggle visibility drawerFour/ }),
30+
},
2931
};
3032

3133
function SetupDrawerWithChildren(props) {
@@ -40,14 +42,23 @@ function SetupDrawerWithChildren(props) {
4042
);
4143
}
4244

45+
interface SetupMultipleDrawersProps {
46+
drawerOneVisibleDefault?: boolean
47+
drawerTwoVisibleDefault?: boolean,
48+
drawerThreeVisibleDefault?: boolean
49+
drawerFourVisibleDefault?: boolean,
50+
}
51+
4352
function SetupMultipleDrawers({
44-
drawerOneVisibleDefault,
45-
drawerTwoVisibleDefault,
46-
drawerThreeVisibleDefault,
47-
}) {
53+
drawerOneVisibleDefault = false,
54+
drawerTwoVisibleDefault = false,
55+
drawerThreeVisibleDefault = false,
56+
drawerFourVisibleDefault = false,
57+
}: SetupMultipleDrawersProps) {
4858
const [isDrawerOneVisible, setIsDrawerOneVisible] = useState(drawerOneVisibleDefault);
4959
const [isDrawerTwoVisible, setIsDrawerTwoVisible] = useState(drawerTwoVisibleDefault);
5060
const [isDrawerThreeVisible, setIsDrawerThreeVisible] = useState(drawerThreeVisibleDefault);
61+
const [isDrawerFourVisible, setIsDrawerFourVisible] = useState(drawerFourVisibleDefault);
5162

5263
return (
5364
<div>
@@ -72,6 +83,13 @@ function SetupMultipleDrawers({
7283
toggle visibility drawerThree
7384
</button>
7485

86+
<button
87+
type="button"
88+
onClick={() => setIsDrawerFourVisible((prevState) => !prevState)}
89+
>
90+
toggle visibility drawerFour
91+
</button>
92+
7593
<Drawer
7694
visible={isDrawerOneVisible}
7795
onRequestClose={() => setIsDrawerOneVisible(false)}
@@ -90,22 +108,20 @@ function SetupMultipleDrawers({
90108
>
91109
<div>childrenDrawerThree</div>
92110
</Drawer>
111+
112+
{/* Testing what happens when drawer unmounts */}
113+
{isDrawerFourVisible && (
114+
<Drawer
115+
visible={isDrawerFourVisible}
116+
onRequestClose={() => setIsDrawerThreeVisible(false)}
117+
>
118+
<div>childrenDrawerFour</div>
119+
</Drawer>
120+
)}
93121
</div>
94122
);
95123
}
96124

97-
SetupMultipleDrawers.propTypes = {
98-
drawerOneVisibleDefault: propTypes.bool,
99-
drawerThreeVisibleDefault: propTypes.bool,
100-
drawerTwoVisibleDefault: propTypes.bool,
101-
};
102-
103-
SetupMultipleDrawers.defaultProps = {
104-
drawerOneVisibleDefault: false,
105-
drawerTwoVisibleDefault: false,
106-
drawerThreeVisibleDefault: false,
107-
};
108-
109125
describe('Drawer', () => {
110126
beforeEach(() => {
111127
// Need to manually clean classList on body since jsdom instance can stay
@@ -270,5 +286,19 @@ describe('Drawer', () => {
270286
});
271287
});
272288
});
289+
290+
describe('when user unmounts the drawer that is open (e.g navigation to a different page)', () => {
291+
it('body tag does not have Drawer--open', async () => {
292+
const { container } = render(<SetupMultipleDrawers drawerFourVisibleDefault />);
293+
294+
userEvent.click(elements.drawerFourToggleVisibilityButton.get());
295+
296+
const body = container.closest('body');
297+
298+
await waitFor(() => {
299+
expect(body?.classList).not.toContain('Drawer--open');
300+
});
301+
});
302+
});
273303
});
274304
});

src/Drawer/Drawer.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ const Drawer = ({
9595
if (hasBackgroundOverlay) {
9696
disableBackgroundScrolling();
9797
}
98+
99+
return () => {
100+
// Cleanup function to remove the class and reset the ref.
101+
// Covers the edge where you navigate to a new page
102+
// from drawer via a link
103+
if (hasBackgroundOverlay) {
104+
document.body.classList.remove('Drawer--open');
105+
isCurrentlyOpen.current = false;
106+
}
107+
};
98108
}, [hasBackgroundOverlay, visible]);
99109

100110
return (

src/Select/AsyncSelect.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { defaultStyles, defaultTheme, SELECT_SIZES } from './styles';
99
const AsyncSelect = ({
1010
'aria-label': ariaLabel,
1111
'aria-labelledby': ariaLabelledBy,
12+
cacheOptions,
1213
className,
14+
closeMenuOnSelect,
1315
components,
1416
defaultOptions,
1517
defaultValue,
@@ -26,7 +28,6 @@ const AsyncSelect = ({
2628
modal,
2729
name,
2830
noOptionsMessage,
29-
placeholder,
3031
size,
3132
value,
3233

@@ -37,8 +38,10 @@ const AsyncSelect = ({
3738
{...props}
3839
aria-label={ariaLabel}
3940
aria-labelledby={ariaLabelledBy}
41+
cacheOptions={cacheOptions}
4042
className={`${className || ''} AsyncSelect`}
4143
classNamePrefix="Select"
44+
closeMenuOnSelect={closeMenuOnSelect}
4245
components={components}
4346
defaultOptions={defaultOptions}
4447
defaultValue={defaultValue}
@@ -54,7 +57,7 @@ const AsyncSelect = ({
5457
menuPortalTarget={modal ? document.body : undefined}
5558
name={name}
5659
noOptionsMessage={noOptionsMessage}
57-
placeholder={placeholder}
60+
placeholder="Search"
5861
shouldShowValue
5962
styles={{
6063
...defaultStyles({ menuWidth, size }),
@@ -75,7 +78,9 @@ const AsyncSelect = ({
7578
AsyncSelect.propTypes = {
7679
'aria-label': propTypes.string,
7780
'aria-labelledby': propTypes.string,
81+
cacheOptions: propTypes.bool,
7882
className: propTypes.string,
83+
closeMenuOnSelect: propTypes.bool,
7984
components: propTypes.any,
8085
defaultOptions: propTypes.oneOfType([propTypes.bool, propTypes.array]),
8186
defaultValue: propTypes.object,
@@ -106,7 +111,9 @@ AsyncSelect.propTypes = {
106111
AsyncSelect.defaultProps = {
107112
'aria-label': undefined,
108113
'aria-labelledby': undefined,
114+
cacheOptions: undefined,
109115
className: undefined,
116+
closeMenuOnSelect: undefined,
110117
components: undefined,
111118
defaultOptions: false,
112119
defaultValue: undefined,
@@ -124,7 +131,6 @@ AsyncSelect.defaultProps = {
124131
placeholder: undefined,
125132
size: SELECT_SIZES.SMALL,
126133
value: undefined,
127-
128134
onChange: undefined,
129135
};
130136

src/Select/AsyncSelect.stories.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
Modal, ModalHeader, ModalBody, ModalFooter,
88
} from 'src/Modal';
99

10+
import Option from './Option';
11+
1012
export default {
1113
title: 'Components/Selects/Async',
1214
component: AsyncSelect,
@@ -90,3 +92,23 @@ export const InModal = () => {
9092
</>
9193
);
9294
};
95+
96+
export const MultiSelect = () => (
97+
<FormGroup
98+
label="Async MultiSelect"
99+
labelHtmlFor="async-multiselect"
100+
>
101+
<AsyncSelect
102+
cacheOptions
103+
closeMenuOnSelect={false}
104+
components={{ Option }}
105+
getOptionLabel={({ label }) => label}
106+
getOptionValue={({ value }) => value}
107+
inputId="async-multiselect"
108+
isClearable
109+
isMulti
110+
loadOptions={loadOptions}
111+
noOptionsMessage={({ inputValue }) => inputValue.length ? 'No results!' : 'Type to search...'}
112+
/>
113+
</FormGroup>
114+
);

src/Select/Option.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ import './Option.scss';
1616
const Option = forwardRef(({ indeterminate, ...props }, ref) => (
1717
<components.Option {...props}>
1818
<div className="Option">
19-
<label>{props.label}</label>
2019
<CheckboxButton
2120
checked={props.isSelected}
21+
className="Checkbox"
2222
id={props.label}
2323
indeterminate={indeterminate}
2424
ref={ref}
2525
onChange={() => null}
2626
/>
27+
<label>{props.label}</label>
2728
</div>
2829
</components.Option>
2930
));

src/Select/Option.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.Option {
2-
display: flex;
3-
justify-content: space-between;
2+
display: flex;
43
align-items: center;
4+
5+
.Checkbox {
6+
margin-right: var(--synth-spacing-3);
7+
}
58
}

0 commit comments

Comments
 (0)