Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX-367 Fix ListBox key events bug #681

Merged
merged 1 commit into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/matchbox/src/components/ListBox/useOptionConstructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ function useOptionConstructor({ options, value, onSelect, open, placeholder }) {
}

function clearKeysSoFarAfterDelay() {
let timeout = setTimeout(function() {
setKeysSoFar('');
setKeyClear(false);
}, 700);

if (keyClear) {
clearTimeout(timeout);
setKeyClear(null);
}

setKeyClear(true);

let timeout = setTimeout(function() {
setKeysSoFar('');
setKeyClear(false);
}, 700);
}

// Preps array of option refs
Expand All @@ -67,15 +67,15 @@ function useOptionConstructor({ options, value, onSelect, open, placeholder }) {
}, [focused]);

React.useLayoutEffect(() => {
if (keysSoFar) {
if (keysSoFar && options) {
const index = options.findIndex(option =>
option.props.value.toLowerCase().startsWith(keysSoFar),
option.props.children.toLowerCase().startsWith(keysSoFar),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, this is searching children (the option label) instead of the value, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

);
if (index >= 0) {
setFocused(index);
}
}
}, [keysSoFar]);
}, [keysSoFar, options]);

const optionsMarkup = (
<>
Expand Down
36 changes: 24 additions & 12 deletions site/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('dotenv').config();
const { flatten } = require('lodash');
const path = require('path');

module.exports = {
siteMetadata: {
Expand Down Expand Up @@ -86,18 +87,29 @@ module.exports = {
resolve: 'gatsby-plugin-alias-imports',
options: {
// Uncomment these aliases if you want to reference local matchbox packages
// alias: {
// '@sparkpost/matchbox': path.resolve(__dirname, '../matchbox/src'),
// '@sparkpost/matchbox-icons': path.resolve(
// __dirname,
// '../matchbox-icons/src'
// ),
// '@sparkpost/design-tokens': path.resolve(
// __dirname,
// '../design-tokens'
// )
// },
// extensions: []
alias:
process.env.LOCAL_MATCHBOX === 'true'
? {
react: path.resolve(__dirname, '../node_modules/react'),
'styled-components': path.resolve(
__dirname,
'../node_modules/styled-components'
),
'@sparkpost/design-tokens': path.resolve(
__dirname,
'../packages/design-tokens'
),
'@sparkpost/matchbox-icons': path.resolve(
__dirname,
'../packages/matchbox-icons/src'
),
'@sparkpost/matchbox': path.resolve(
__dirname,
'../packages/matchbox/src'
)
}
: {},
extensions: []
}
},
process.env.GATSBY_ACTIVE_ENV === 'index'
Expand Down
3 changes: 2 additions & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"develop": "gatsby develop -p 8001",
"format": "prettier --write src/**/*.{js,jsx}",
"start": "npm run develop",
"start:localMatchbox": "LOCAL_MATCHBOX=true npm run develop",
"serve": "gatsby serve",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\"",
"index": "GATSBY_ACTIVE_ENV=index gatsby build"
Expand All @@ -65,4 +66,4 @@
"bugs": {
"url": "https://github.com/SparkPost/matchbox/issues"
}
}
}