Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
common
Commits
e2ed0fac
Commit
e2ed0fac
authored
Oct 15, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Исправлена реакция AutoComplete на клики мыши
parent
c34b92b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
6 deletions
+15
-6
AutoComplete.tsx
+3
-5
AutoComplete/state-machine.ts
+12
-1
No files found.
AutoComplete.tsx
View file @
e2ed0fac
...
...
@@ -63,8 +63,8 @@ export default class AutoComplete<A=string> extends React.Component<Props<A>, St
// Выполнение действий из ST
dispatch
=
(
action
:
ST
.
Action
<
A
>
)
=>
{
const
{
ctx
,
openOnFocus
,
source
}
=
this
.
props
;
const
acCtx
=
{
...
ctx
,
options
:
{
openOnFocus
,
source
}
};
const
{
ctx
,
openOnFocus
,
openOnClick
,
source
}
=
this
.
props
;
const
acCtx
=
{
...
ctx
,
options
:
{
openOnFocus
,
openOnClick
,
source
}
};
this
.
setState
(
prev
=>
{
const
[
next
,
command
]
=
ST
.
update
(
acCtx
,
action
,
prev
);
command
.
subscribe
(
ethr
=>
ethr
.
tag
===
'Right'
&&
this
.
dispatch
(
ethr
.
value
));
...
...
@@ -98,9 +98,7 @@ export default class AutoComplete<A=string> extends React.Component<Props<A>, St
};
handleClick
=
(
e
?:
React
.
SyntheticEvent
)
=>
{
const
{
openOnClick
}
=
this
.
props
;
const
{
open
}
=
this
.
state
;
if
(
openOnClick
&&
!
open
)
this
.
dispatch
({
tag
:
'Open'
});
this
.
dispatch
({
tag
:
'Click'
});
};
handleToggleVisibility
=
()
=>
{
...
...
AutoComplete/state-machine.ts
View file @
e2ed0fac
...
...
@@ -15,6 +15,7 @@ export type Options<A> = {
printItem
?(
x
:
A
):
string
;
limit
?:
number
;
openOnFocus
?:
boolean
;
openOnClick
?:
boolean
;
};
...
...
@@ -57,6 +58,7 @@ export type Action<A> =
|
{
tag
:
'Blur'
}
|
{
tag
:
'Close'
}
|
{
tag
:
'Open'
}
|
{
tag
:
'Click'
}
// State
...
...
@@ -131,7 +133,9 @@ export function update<A>(ctx: Ctx<A>, action: Action<A>, state: State<A>): [Sta
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
{
...
state
.
query
,
search
:
action
.
value
}
})];
}
case
'Focus'
:
{
if
(
ctx
.
options
.
openOnFocus
)
{
if
(
ctx
.
options
.
openOnFocus
&&
!
ctx
.
options
.
openOnClick
)
{
// Не открываем попап на фокусе если указан
// `ctx.options.openOnClick`, тк он откроется на клике
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
state
.
query
})];
}
return
[
state
,
noop
];
...
...
@@ -146,6 +150,13 @@ export function update<A>(ctx: Ctx<A>, action: Action<A>, state: State<A>): [Sta
if
(
state
.
open
)
return
[
state
,
noop
];
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
defaultQuery
})];
}
case
'Click'
:
{
if
(
ctx
.
options
.
openOnClick
)
{
if
(
state
.
open
)
return
[{
...
state
,
open
:
false
},
noop
];
return
[
state
,
cmd
.
of
<
Action
<
A
>>
({
tag
:
'Query'
,
query
:
defaultQuery
})];
}
return
[
state
,
noop
];
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment