Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
253ea968
Commit
253ea968
authored
7 years ago
by
Tom Robinson
Browse files
Options
Downloads
Patches
Plain Diff
TokenField should blur on tab when multi=false
parent
33576c61
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/components/TokenField.jsx
+4
-2
4 additions, 2 deletions
frontend/src/metabase/components/TokenField.jsx
frontend/test/components/TokenField.unit.spec.js
+34
-0
34 additions, 0 deletions
frontend/test/components/TokenField.unit.spec.js
with
38 additions
and
2 deletions
frontend/src/metabase/components/TokenField.jsx
+
4
−
2
View file @
253ea968
...
...
@@ -284,8 +284,10 @@ export default class TokenField extends Component {
}
else
if
(
this
.
props
.
parseFreeformValue
)
{
// if we previously updated on input change then we don't need to do it again,
if
(
this
.
props
.
updateOnInputChange
)
{
// also prevent the input from changing due to this key press
e
.
preventDefault
();
// if multi=true also prevent the input from changing due to this key press
if
(
multi
)
{
e
.
preventDefault
();
}
// and clear the input
this
.
clearInputValue
()
// return false so we don't stop the keyDown from propagating in case we're listening
...
...
This diff is collapsed.
Click to expand it.
frontend/test/components/TokenField.unit.spec.js
+
34
−
0
View file @
253ea968
...
...
@@ -261,4 +261,38 @@ describe("TokenField", () => {
})
)
})
describe
(
"
with multi=true
"
,
()
=>
{
it
(
"
should prevent blurring on tab
"
,
()
=>
{
const
preventDefault
=
jest
.
fn
()
const
component
=
mount
(
<
TokenFieldWithStateAndDefaults
options
=
{
DEFAULT_OPTIONS
}
// return null for empty string since it's not a valid
parseFreeformValue
=
{(
value
)
=>
value
||
null
}
updateOnInputChange
multi
/>
)
const
input
=
component
.
find
(
"
input
"
);
input
.
simulate
(
"
focus
"
);
input
.
simulate
(
"
change
"
,
{
target
:
{
value
:
"
asdf
"
}
});
input
.
simulate
(
"
keydown
"
,
{
keyCode
:
KEYCODE_TAB
,
preventDefault
:
preventDefault
})
expect
(
preventDefault
).
toHaveBeenCalled
();
})
})
describe
(
"
with multi=false
"
,
()
=>
{
it
(
"
should not prevent blurring on tab
"
,
()
=>
{
const
preventDefault
=
jest
.
fn
()
const
component
=
mount
(
<
TokenFieldWithStateAndDefaults
options
=
{
DEFAULT_OPTIONS
}
// return null for empty string since it's not a valid
parseFreeformValue
=
{(
value
)
=>
value
||
null
}
updateOnInputChange
/>
)
const
input
=
component
.
find
(
"
input
"
);
input
.
simulate
(
"
focus
"
);
input
.
simulate
(
"
change
"
,
{
target
:
{
value
:
"
asdf
"
}
});
input
.
simulate
(
"
keydown
"
,
{
keyCode
:
KEYCODE_TAB
,
preventDefault
:
preventDefault
})
expect
(
preventDefault
).
not
.
toHaveBeenCalled
();
})
})
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment