Skip to content

Commit

Permalink
feat(js): turn search label into submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Dec 2, 2020
1 parent 1656530 commit 27e61cb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
5 changes: 4 additions & 1 deletion examples/js/autocomplete.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
cursor: initial;
display: flex;
height: 100%;
padding: 0 0.5rem;
position: absolute;
z-index: 2;
}
Expand Down Expand Up @@ -57,12 +56,16 @@
outline: currentcolor none medium;
}

.aa-SubmitButton,
.aa-ResetButton {
background: none;
border: 0;
cursor: pointer;
height: 100%;
padding: 0 0.5rem;
}

.aa-ResetButton {
position: absolute;
right: 0;
z-index: 2;
Expand Down
4 changes: 0 additions & 4 deletions packages/autocomplete-js/src/components/Label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { AutocompleteApi as AutocompleteCoreApi } from '@algolia/autocomplete-co
import { Component, WithClassNames } from '../types/Component';
import { concatClassNames, setProperties } from '../utils';

import { SearchIcon } from './SearchIcon';

type LabelProps = WithClassNames<
ReturnType<AutocompleteCoreApi<any>['getLabelProps']>
>;
Expand All @@ -19,7 +17,5 @@ export const Label: Component<LabelProps, HTMLLabelElement> = ({
class: concatClassNames(['aa-Label', classNames.label]),
});

element.appendChild(SearchIcon({}));

return element;
};
20 changes: 20 additions & 0 deletions packages/autocomplete-js/src/components/SubmitButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, WithClassNames } from '../types/Component';
import { concatClassNames, setProperties } from '../utils';

import { SearchIcon } from './SearchIcon';

type SubmitButtonProps = WithClassNames<{}>;

export const SubmitButton: Component<SubmitButtonProps, HTMLButtonElement> = ({
classNames,
}) => {
const element = document.createElement('button');
setProperties(element, {
type: 'submit',
class: concatClassNames(['aa-SubmitButton', classNames.submitButton]),
});

element.appendChild(SearchIcon({}));

return element;
};
1 change: 1 addition & 0 deletions packages/autocomplete-js/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './SourceFooter';
export * from './SourceHeader';
export * from './SourceItem';
export * from './SourceList';
export * from './SubmitButton';
4 changes: 4 additions & 0 deletions packages/autocomplete-js/src/createAutocompleteDom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Panel,
ResetButton,
Root,
SubmitButton,
} from './components';
import { AutocompleteClassNames, AutocompleteDom } from './types';

Expand All @@ -30,10 +31,12 @@ export function createAutocompleteDom<TItem extends BaseItem>({
const inputWrapper = InputWrapper({ classNames });
const label = Label({ classNames, ...getLabelProps({}) });
const input = Input({ classNames, getInputProps });
const submitButton = SubmitButton({ classNames });
const resetButton = ResetButton({ classNames });
const form = Form({ classNames, ...getFormProps({ inputElement: input }) });
const panel = Panel({ classNames, ...getPanelProps({}) });

label.appendChild(submitButton);
inputWrapper.appendChild(input);
inputWrapper.appendChild(label);
inputWrapper.appendChild(resetButton);
Expand All @@ -46,6 +49,7 @@ export function createAutocompleteDom<TItem extends BaseItem>({
root,
form,
label,
submitButton,
resetButton,
panel,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/autocomplete-js/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type AutocompleteClassNames = Partial<{
label: string;
inputWrapper: string;
input: string;
submitButton: string;
resetButton: string;
panel: string;
panelLayout: string;
Expand All @@ -88,6 +89,7 @@ export type AutocompleteDom = {
root: HTMLDivElement;
form: HTMLFormElement;
label: HTMLLabelElement;
submitButton: HTMLButtonElement;
resetButton: HTMLButtonElement;
panel: HTMLDivElement;
};
Expand Down

0 comments on commit 27e61cb

Please sign in to comment.