-
Notifications
You must be signed in to change notification settings - Fork 64
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
1565 - Add typeahead dropdown icon/button #1735
Changes from 6 commits
7077ec8
e79a5e5
26a37b2
396c053
3e26314
e42b173
21d73ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export const root: string; | ||
export const triggerWrapper: string; | ||
export const arrow: string; | ||
export const inputTrailing: string; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
export const root: string; | ||
export const arrow: string; | ||
export const expanded: string; | ||
export const iconDownIcon: string; | ||
export const focused: string; | ||
export const inputTrailing: string; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ import { Keys } from '../common/util'; | |
import LoadingIndicator from '../loading-indicator'; | ||
import * as inputCss from '../theme/default/text-input.m.css'; | ||
import { find } from '@dojo/framework/shim/array'; | ||
import Icon from '../icon'; | ||
import * as iconCss from '../theme/default/icon.m.css'; | ||
|
||
export interface TypeaheadProperties { | ||
/** Callback called when user selects a value */ | ||
|
@@ -53,6 +55,8 @@ export interface TypeaheadProperties { | |
itemDisabled?: ListProperties['disabled']; | ||
/** Flag to indicate if values other than those in the resource can be entered, defaults to true */ | ||
strict?: boolean; | ||
/** Flag to indicate if drop down arrow should be shown in trailing section of text input, defaults to false */ | ||
hasDownArrow?: boolean; | ||
} | ||
|
||
export interface TypeaheadICache { | ||
|
@@ -62,6 +66,7 @@ export interface TypeaheadICache { | |
activeIndex: number; | ||
dirty: boolean; | ||
expanded: boolean; | ||
focused: boolean; | ||
focusNode: string; | ||
initial: string; | ||
valid: boolean | undefined; | ||
|
@@ -113,7 +118,8 @@ export const Typeahead = factory(function Typeahead({ | |
}, | ||
classes, | ||
theme: themeProp, | ||
variant | ||
variant, | ||
hasDownArrow | ||
} = properties(); | ||
const { | ||
get, | ||
|
@@ -289,6 +295,9 @@ export const Typeahead = factory(function Typeahead({ | |
} | ||
} | ||
|
||
const expanded = icache.get('expanded'); | ||
const focused = icache.get('focused'); | ||
|
||
return ( | ||
<div | ||
key="root" | ||
|
@@ -297,7 +306,9 @@ export const Typeahead = factory(function Typeahead({ | |
themedCss.root, | ||
disabled && themedCss.disabled, | ||
valid === true && themedCss.valid, | ||
valid === false && themedCss.invalid | ||
valid === false && themedCss.invalid, | ||
expanded && themedCss.expanded, | ||
focused && themedCss.focused | ||
]} | ||
> | ||
<TriggerPopup | ||
|
@@ -359,10 +370,12 @@ export const Typeahead = factory(function Typeahead({ | |
)} | ||
onFocus={() => { | ||
const { onFocus } = properties(); | ||
icache.set('focused', true); | ||
onFocus && onFocus(); | ||
}} | ||
onBlur={() => { | ||
const { onBlur } = properties(); | ||
icache.set('focused', false); | ||
if (!strict) { | ||
const value = icache.getOrSet('labelValue', ''); | ||
const currentOption = icache.get('selectedOption'); | ||
|
@@ -419,7 +432,39 @@ export const Typeahead = factory(function Typeahead({ | |
}} | ||
valid={valid} | ||
> | ||
{{ label, leading }} | ||
{{ | ||
label, | ||
leading, | ||
trailing: hasDownArrow && ( | ||
<button | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We couldn't use the dojo button here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is following the same pattern that the |
||
type="button" | ||
disabled={disabled} | ||
classes={themedCss.arrow} | ||
onclick={openMenu} | ||
onkeydown={(event) => { | ||
if ( | ||
event.which === Keys.Down || | ||
event.which === Keys.Space || | ||
event.which === Keys.Enter | ||
) { | ||
event.preventDefault(); | ||
openMenu(); | ||
} | ||
}} | ||
> | ||
<Icon | ||
type="downIcon" | ||
theme={theme.compose( | ||
iconCss, | ||
css, | ||
'icon' | ||
)} | ||
classes={classes} | ||
variant={variant} | ||
/> | ||
</button> | ||
) | ||
}} | ||
</TextInput> | ||
); | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need these? doesn't the build generate these for us? cc @matt-gadd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not appear to. I just tested removing them and they are not in the end product.
Several other widgets have them in their css too.