Skip to content

Commit e8111ea

Browse files
authored
styles(compass-query-bar): Update filter label placement and spacing styles COMPASS-6088 (#3437)
1 parent 16cc7e7 commit e8111ea

File tree

4 files changed

+57
-34
lines changed

4 files changed

+57
-34
lines changed

packages/compass-query-bar/src/components/query-bar.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
spacing,
99
uiColors,
1010
withTheme,
11+
Label,
1112
} from '@mongodb-js/compass-components';
1213
import type { Listenable } from 'reflux';
1314
import type AppRegistry from 'hadron-app-registry';
@@ -17,7 +18,10 @@ import type {
1718
QueryBarOptionProps,
1819
} from '../constants/query-option-definition';
1920
import { OPTION_DEFINITION } from '../constants/query-option-definition';
20-
import { QueryOption as QueryOptionComponent } from './query-option';
21+
import {
22+
QueryOption as QueryOptionComponent,
23+
queryOptionLabelContainerStyles,
24+
} from './query-option';
2125
import { QueryOptionsGrid } from './query-options-grid';
2226
import { QueryHistoryButtonPopover } from './query-history-button-popover';
2327

@@ -40,12 +44,17 @@ const queryBarFirstRowStyles = css({
4044
display: 'flex',
4145
alignItems: 'flex-start',
4246
gap: spacing[2],
47+
paddingLeft: spacing[2],
4348
});
4449

4550
const filterContainerStyles = css({
4651
flexGrow: 1,
4752
});
4853

54+
const filterLabelStyles = css({
55+
padding: 0,
56+
});
57+
4958
type QueryBarProps = {
5059
buttonLabel?: string;
5160
darkMode?: boolean;
@@ -112,6 +121,8 @@ const UnthemedQueryBar: React.FunctionComponent<QueryBarProps> = ({
112121
[onApply]
113122
);
114123

124+
const filterQueryOptionId = 'query-bar-option-input-filter';
125+
115126
return (
116127
<form
117128
className={cx(queryBarFormStyles, darkMode && queryBarFormDarkStyles)}
@@ -121,16 +132,26 @@ const UnthemedQueryBar: React.FunctionComponent<QueryBarProps> = ({
121132
data-result-id={resultId}
122133
>
123134
<div className={queryBarFirstRowStyles}>
124-
{showQueryHistoryButton && (
125-
<QueryHistoryButtonPopover
126-
localAppRegistry={localAppRegistry}
127-
globalAppRegistry={globalAppRegistry}
128-
/>
129-
)}
135+
<div className={queryOptionLabelContainerStyles}>
136+
<Label
137+
htmlFor={filterQueryOptionId}
138+
id="query-bar-option-input-filter-label"
139+
className={filterLabelStyles}
140+
>
141+
Filter
142+
</Label>
143+
{showQueryHistoryButton && (
144+
<QueryHistoryButtonPopover
145+
localAppRegistry={localAppRegistry}
146+
globalAppRegistry={globalAppRegistry}
147+
/>
148+
)}
149+
</div>
130150
<div className={filterContainerStyles}>
131151
<QueryOptionComponent
132152
hasError={!queryOptionProps.filterValid}
133153
queryOption="filter"
154+
id={filterQueryOptionId}
134155
onChange={(value: string) => onChangeQueryOption('filter', value)}
135156
onApply={onApply}
136157
placeholder={

packages/compass-query-bar/src/components/query-history-button-popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const openQueryHistoryButtonStyles = cx(
1919
display: 'inline-flex',
2020
alignItems: 'center',
2121
padding: spacing[2] - 2, // -2px for border.
22+
marginLeft: spacing[1],
2223
'&:hover': {
2324
cursor: 'pointer',
2425
},
@@ -31,7 +32,6 @@ const queryHistoryPopoverStyles = css({
3132
maxHeight: 'calc(100vh - 270px)',
3233
marginTop: spacing[1],
3334
display: 'flex',
34-
marginLeft: -spacing[2] - 1, // Align to the left of the query bar.
3535
});
3636

3737
type QueryHistoryProps = {

packages/compass-query-bar/src/components/query-option.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import type { QueryOption as QueryOptionType } from '../constants/query-option-d
1717
const queryOptionStyles = css({
1818
display: 'flex',
1919
position: 'relative',
20-
alignItems: 'center',
20+
alignItems: 'flex-start',
2121
});
2222

2323
const queryOptionLabelStyles = css({
2424
// A bit of vertical padding so users can click the label easier.
25-
padding: `${spacing[2]}px 0`,
25+
paddingTop: spacing[1],
2626
marginRight: spacing[2],
2727
});
2828

@@ -50,17 +50,19 @@ const optionInputWithErrorStyles = css({
5050
},
5151
});
5252

53-
const queryOptionLabelContainerStyles = css({
54-
whiteSpace: 'nowrap',
53+
export const queryOptionLabelContainerStyles = css({
54+
// Hardcoded height as we want the label not to vertically
55+
// center on the input area when it's expanded.
56+
height: spacing[4] + spacing[1],
5557
textTransform: 'capitalize',
56-
alignItems: 'center',
5758
display: 'flex',
58-
margin: 0,
59+
alignItems: 'center',
5960
});
6061

6162
type QueryOptionProps = {
6263
darkMode?: boolean;
6364
hasError: boolean;
65+
id: string;
6466
onChange: (value: string) => void;
6567
onApply: () => void;
6668
placeholder?: string;
@@ -76,6 +78,7 @@ const UnthemedQueryOption: React.FunctionComponent<QueryOptionProps> = ({
7678
hasError,
7779
onApply,
7880
onChange,
81+
id,
7982
placeholder = '',
8083
queryOption,
8184
refreshEditorAction,
@@ -93,26 +96,23 @@ const UnthemedQueryOption: React.FunctionComponent<QueryOptionProps> = ({
9396
className={queryOptionStyles}
9497
data-testid={`query-bar-option-${queryOption}`}
9598
>
96-
<div
97-
className={queryOptionLabelContainerStyles}
98-
data-testid="query-bar-option-label"
99-
>
100-
<Label
101-
htmlFor={`query-bar-option-input-${queryOption}`}
102-
id={`query-bar-option-input-${queryOption}-label`}
103-
className={queryOptionLabelStyles}
104-
// We hide the `Filter` label, but keep it in the dom for
105-
// screen reader label support.
106-
hidden={queryOption === 'filter'}
107-
>
108-
{queryOption}
109-
</Label>
110-
</div>
99+
{/* The filter label is shown by the query bar. */}
100+
{queryOption !== 'filter' && (
101+
<div className={queryOptionLabelContainerStyles}>
102+
<Label
103+
htmlFor={id}
104+
id={`query-bar-option-input-${queryOption}-label`}
105+
className={queryOptionLabelStyles}
106+
>
107+
{queryOption}
108+
</Label>
109+
</div>
110+
)}
111111
<div className={cx(isDocumentEditor && documentEditorOptionStyles)}>
112112
{isDocumentEditor ? (
113113
<OptionEditor
114114
hasError={hasError}
115-
id={`query-bar-option-input-${queryOption}`}
115+
id={id}
116116
queryOption={queryOption}
117117
onApply={onApply}
118118
onChange={onChange}
@@ -125,7 +125,7 @@ const UnthemedQueryOption: React.FunctionComponent<QueryOptionProps> = ({
125125
) : (
126126
<TextInput
127127
aria-labelledby={`query-bar-option-input-${queryOption}-label`}
128-
id={`query-bar-option-input-${queryOption}`}
128+
id={id}
129129
data-testid="query-bar-option-input"
130130
className={cx(
131131
darkMode

packages/compass-query-bar/src/components/query-options-grid.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { OPTION_DEFINITION } from '../constants/query-option-definition';
1010
import { QueryOption as QueryOptionComponent } from './query-option';
1111

1212
const gridStyles = css({
13-
alignItems: 'center',
13+
alignItems: 'flex-start',
1414
display: 'grid',
1515
flexGrow: 1,
1616
position: 'relative',
17-
marginTop: spacing[1] + 2,
17+
marginTop: spacing[2],
1818
padding: `0 ${spacing[2]}px`,
19-
gap: `${spacing[1]}px ${spacing[2]}px`,
19+
gap: spacing[2],
2020
gridTemplateColumns: 'repeat(6, 1fr)',
2121
});
2222

@@ -191,6 +191,7 @@ export const QueryOptionsGrid: React.FunctionComponent<
191191
hasError={!queryOptionProps[`${optionName}Valid`]}
192192
onChange={(value: string) => onChangeQueryOption(optionName, value)}
193193
onApply={onApply}
194+
id={`query-bar-option-input-${optionName}`}
194195
placeholder={
195196
queryOptionProps[`${optionName}Placeholder`] ||
196197
OPTION_DEFINITION[optionName].placeholder
@@ -213,6 +214,7 @@ export const QueryOptionsGrid: React.FunctionComponent<
213214
<QueryOptionComponent
214215
hasError={!queryOptionProps[`${optionName}Valid`]}
215216
key={`numeric-query-option-${optionName}`}
217+
id={`query-bar-option-input-${optionName}`}
216218
onChange={(value: string) => onChangeQueryOption(optionName, value)}
217219
onApply={onApply}
218220
placeholder={

0 commit comments

Comments
 (0)