Skip to content

Commit acdf7ee

Browse files
authored
fix(topbar): only close drawer on application change with new callback (#358)
1 parent fa445ed commit acdf7ee

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

components/topbar/src/application-drawer-v1.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export const ApplicationDrawerV1 = ({
207207
applicationId,
208208
content,
209209
onChange,
210+
onChangeAndClose,
210211
applicationArea,
211212
}: ApplicationDrawerProps & { applicationArea: ApplicationArea }) => {
212213
const { t } = useTranslation();
@@ -216,9 +217,15 @@ export const ApplicationDrawerV1 = ({
216217

217218
const onClickItem = (id: string) => {
218219
if (id !== currentSelection?.id) {
219-
onChange(id);
220+
if (onChangeAndClose) {
221+
onChangeAndClose(id);
222+
setIsOpen(false);
223+
} else {
224+
onChange?.(id);
225+
}
226+
} else {
227+
setIsOpen(false);
220228
}
221-
setIsOpen(false);
222229
};
223230

224231
return (

components/topbar/src/application-drawer-v2.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,23 @@ export const ApplicationDrawerV2 = ({
171171
applicationId,
172172
content,
173173
onChange,
174+
onChangeAndClose,
174175
}: ApplicationDrawerProps & { applicationArea: ApplicationArea }) => {
175176
const [isOpen, setIsOpen] = useState(false);
176177
const styles = useApplicationDrawerV2Styles();
177178
const currentSelection = findCurrent(applicationId, content);
178179

179180
const onClickItem = (id: string) => {
180181
if (id !== currentSelection?.id) {
181-
onChange(id);
182+
if (onChangeAndClose) {
183+
onChangeAndClose(id);
184+
setIsOpen(false);
185+
} else {
186+
onChange?.(id);
187+
}
188+
} else {
189+
setIsOpen(false);
182190
}
183-
setIsOpen(false);
184191
};
185192

186193
return (

components/topbar/src/application-drawer.types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,10 @@ export type ApplicationDrawerProps = {
4040
title: JSX.Element;
4141
content?: ApplicationDrawerContent[];
4242
applicationId: string;
43-
onChange: (id: string) => void;
43+
onChange?: (id: string) => void;
44+
/**
45+
* Supply this function if you want the drawer to close the drawer after the action.
46+
* Supplying this function will cause onChange callback function to be ignored.
47+
*/
48+
onChangeAndClose?: (id: string) => void;
4449
};

0 commit comments

Comments
 (0)