Merge branch 'develop' into feature/account-menu-react

This commit is contained in:
Antonella Sgarlatta
2021-07-01 16:58:50 -03:00
5 changed files with 74 additions and 48 deletions

View File

@@ -62,6 +62,7 @@ export const AutocompleteTagHint = observer(
onFocus={onFocus} onFocus={onFocus}
onBlur={onBlur} onBlur={onBlur}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
tabIndex={-1}
> >
<span>Create new tag:</span> <span>Create new tag:</span>
<span className="bg-contrast rounded text-xs color-text py-1 pl-1 pr-2 flex items-center ml-2"> <span className="bg-contrast rounded text-xs color-text py-1 pl-1 pr-2 flex items-center ml-2">

View File

@@ -25,10 +25,10 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
const [dropdownMaxHeight, setDropdownMaxHeight] = const [dropdownMaxHeight, setDropdownMaxHeight] =
useState<number | 'auto'>('auto'); useState<number | 'auto'>('auto');
const dropdownRef = useRef<HTMLDivElement>(); const containerRef = useRef<HTMLDivElement>();
const inputRef = useRef<HTMLInputElement>(); const inputRef = useRef<HTMLInputElement>();
const [closeOnBlur] = useCloseOnBlur(dropdownRef, (visible: boolean) => { const [closeOnBlur] = useCloseOnBlur(containerRef, (visible: boolean) => {
setDropdownVisible(visible); setDropdownVisible(visible);
appState.noteTags.clearAutocompleteSearch(); appState.noteTags.clearAutocompleteSearch();
}); });
@@ -69,7 +69,9 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
case 'ArrowDown': case 'ArrowDown':
event.preventDefault(); event.preventDefault();
if (autocompleteTagResults.length > 0) { if (autocompleteTagResults.length > 0) {
appState.noteTags.setFocusedTagResultUuid(autocompleteTagResults[0].uuid); appState.noteTags.setFocusedTagResultUuid(
autocompleteTagResults[0].uuid
);
} else if (autocompleteTagHintVisible) { } else if (autocompleteTagHintVisible) {
appState.noteTags.setAutocompleteTagHintFocused(true); appState.noteTags.setAutocompleteTagHintFocused(true);
} }
@@ -92,54 +94,64 @@ export const AutocompleteTagInput = observer(({ appState }: Props) => {
useEffect(() => { useEffect(() => {
if (autocompleteInputFocused) { if (autocompleteInputFocused) {
inputRef.current.focus(); inputRef.current.focus();
appState.noteTags.setAutocompleteInputFocused(false);
} }
}, [appState.noteTags, autocompleteInputFocused]); }, [appState.noteTags, autocompleteInputFocused]);
return ( return (
<form <div ref={containerRef}>
onSubmit={onFormSubmit} <form
className={`${tags.length > 0 ? 'mt-2' : ''}`} onSubmit={onFormSubmit}
> className={`${tags.length > 0 ? 'mt-2' : ''}`}
<Disclosure open={dropdownVisible} onChange={showDropdown}> >
<input <Disclosure open={dropdownVisible} onChange={showDropdown}>
ref={inputRef} <input
className={`${tags.length > 0 ? 'w-80' : 'w-70 mr-10'} bg-transparent text-xs ref={inputRef}
className={`${
tags.length > 0 ? 'w-80' : 'w-70 mr-10'
} bg-transparent text-xs
color-text no-border h-7 focus:outline-none focus:shadow-none focus:border-bottom`} color-text no-border h-7 focus:outline-none focus:shadow-none focus:border-bottom`}
value={autocompleteSearchQuery} value={autocompleteSearchQuery}
onChange={onSearchQueryChange} onChange={onSearchQueryChange}
type="text" type="text"
placeholder="Add tag" placeholder="Add tag"
onBlur={onBlur} onBlur={onBlur}
onFocus={onFocus} onFocus={onFocus}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
/> tabIndex={tags.length === 0 ? 0 : -1}
{dropdownVisible && (autocompleteTagResults.length > 0 || autocompleteTagHintVisible) && ( />
<DisclosurePanel {dropdownVisible &&
ref={dropdownRef} (autocompleteTagResults.length > 0 ||
className={`${tags.length > 0 ? 'w-80' : 'w-70 mr-10'} sn-dropdown flex flex-col py-2 absolute`} autocompleteTagHintVisible) && (
style={{ maxHeight: dropdownMaxHeight, maxWidth: tagsContainerMaxWidth }} <DisclosurePanel
onBlur={closeOnBlur} className={`${
> tags.length > 0 ? 'w-80' : 'w-70 mr-10'
<div className="overflow-y-auto"> } sn-dropdown flex flex-col py-2 absolute`}
{autocompleteTagResults.map((tagResult: SNTag) => ( style={{
<AutocompleteTagResult maxHeight: dropdownMaxHeight,
key={tagResult.uuid} maxWidth: tagsContainerMaxWidth,
appState={appState} }}
tagResult={tagResult} onBlur={closeOnBlur}
closeOnBlur={closeOnBlur} >
/> <div className="overflow-y-auto">
))} {autocompleteTagResults.map((tagResult: SNTag) => (
</div> <AutocompleteTagResult
{autocompleteTagHintVisible && ( key={tagResult.uuid}
<AutocompleteTagHint appState={appState}
appState={appState} tagResult={tagResult}
closeOnBlur={closeOnBlur} closeOnBlur={closeOnBlur}
/> />
))}
</div>
{autocompleteTagHintVisible && (
<AutocompleteTagHint
appState={appState}
closeOnBlur={closeOnBlur}
/>
)}
</DisclosurePanel>
)} )}
</DisclosurePanel> </Disclosure>
)} </form>
</Disclosure> </div>
</form>
); );
}); });

View File

@@ -82,6 +82,7 @@ export const AutocompleteTagResult = observer(
onFocus={onFocus} onFocus={onFocus}
onBlur={onBlur} onBlur={onBlur}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
tabIndex={-1}
> >
<Icon type="hashtag" className="color-neutral mr-2 min-h-5 min-w-5" /> <Icon type="hashtag" className="color-neutral mr-2 min-h-5 min-w-5" />
<span className="whitespace-nowrap overflow-hidden overflow-ellipsis"> <span className="whitespace-nowrap overflow-hidden overflow-ellipsis">

View File

@@ -10,7 +10,7 @@ type Props = {
}; };
export const NoteTag = observer(({ appState, tag }: Props) => { export const NoteTag = observer(({ appState, tag }: Props) => {
const { focusedTagUuid, tags } = appState.noteTags; const { autocompleteInputFocused, focusedTagUuid, tags } = appState.noteTags;
const [showDeleteButton, setShowDeleteButton] = useState(false); const [showDeleteButton, setShowDeleteButton] = useState(false);
const [tagClicked, setTagClicked] = useState(false); const [tagClicked, setTagClicked] = useState(false);
@@ -51,6 +51,16 @@ export const NoteTag = observer(({ appState, tag }: Props) => {
} }
}; };
const getTabIndex = () => {
if (focusedTagUuid) {
return focusedTagUuid === tag.uuid ? 0 : -1;
}
if (autocompleteInputFocused) {
return -1;
}
return tags[0].uuid === tag.uuid ? 0 : -1;
};
const onKeyDown = (event: KeyboardEvent) => { const onKeyDown = (event: KeyboardEvent) => {
const tagIndex = appState.noteTags.getTagIndex(tag, tags); const tagIndex = appState.noteTags.getTagIndex(tag, tags);
switch (event.key) { switch (event.key) {
@@ -75,7 +85,6 @@ export const NoteTag = observer(({ appState, tag }: Props) => {
useEffect(() => { useEffect(() => {
if (focusedTagUuid === tag.uuid) { if (focusedTagUuid === tag.uuid) {
tagRef.current.focus(); tagRef.current.focus();
appState.noteTags.setFocusedTagUuid(undefined);
} }
}, [appState.noteTags, focusedTagUuid, tag]); }, [appState.noteTags, focusedTagUuid, tag]);
@@ -87,6 +96,7 @@ export const NoteTag = observer(({ appState, tag }: Props) => {
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
onFocus={onFocus} onFocus={onFocus}
onBlur={onBlur} onBlur={onBlur}
tabIndex={getTabIndex()}
> >
<Icon type="hashtag" className="sn-icon--small color-info mr-1" /> <Icon type="hashtag" className="sn-icon--small color-info mr-1" />
<span className="whitespace-nowrap overflow-hidden overflow-ellipsis max-w-290px"> <span className="whitespace-nowrap overflow-hidden overflow-ellipsis max-w-290px">
@@ -99,6 +109,7 @@ export const NoteTag = observer(({ appState, tag }: Props) => {
className="ml-2 -mr-1 border-0 p-0 bg-transparent cursor-pointer flex" className="ml-2 -mr-1 border-0 p-0 bg-transparent cursor-pointer flex"
onBlur={onBlur} onBlur={onBlur}
onClick={onDeleteTagClick} onClick={onDeleteTagClick}
tabIndex={-1}
> >
<Icon <Icon
type="close" type="close"

View File

@@ -113,6 +113,7 @@ export const Strings = {
openAccountMenu: 'Open Account Menu', openAccountMenu: 'Open Account Menu',
trashNotesTitle: 'Move to Trash', trashNotesTitle: 'Move to Trash',
trashNotesText: 'Are you sure you want to move these notes to the trash?', trashNotesText: 'Are you sure you want to move these notes to the trash?',
enterPasscode: 'Please enter a passcode.',
}; };
export const StringUtils = { export const StringUtils = {