Skip to content

Commit 6818928

Browse files
ToMESSKaHerrTopi
authored andcommitted
feat(shared-types,ui-options,ui-select): allow to change font weight of selected option item in Select
Closes: INSTUI-4394
1 parent dee9abb commit 6818928

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

packages/shared-types/src/ComponentThemeVariables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ export type OptionsItemTheme = {
912912
descriptionLineHeight: Typography['lineHeight']
913913
descriptionPaddingStart: string | 0
914914
descriptionColor: Colors['contrasts']['grey4570']
915+
fontWeightSelected: Typography['fontWeightNormal']
915916
}
916917

917918
export type OptionsSeparatorTheme = {

packages/ui-options/src/Options/Item/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class Item extends Component<OptionsItemProps> {
6161
role: 'listitem',
6262
voiceoverRoleBugWorkaround: false,
6363
beforeLabelContentVAlign: 'center',
64-
afterLabelContentVAlign: 'center'
64+
afterLabelContentVAlign: 'center',
65+
isSelected: false
6566
} as const
6667

6768
ref: Element | null = null

packages/ui-options/src/Options/Item/props.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ type OptionsItemOwnProps = OptionsItemRenderProps & {
9494
* provides a reference to the underlying html root element
9595
*/
9696
elementRef?: (element: Element | null) => void
97+
/**
98+
* Whether or not this option is selected
99+
*/
100+
isSelected?: boolean
97101
}
98102

99103
type PropKeys = keyof OptionsItemOwnProps
@@ -133,7 +137,8 @@ const propTypes: PropValidators<PropKeys> = {
133137
href: PropTypes.string,
134138
voiceoverRoleBugWorkaround: PropTypes.bool,
135139
elementRef: PropTypes.func,
136-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
140+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
141+
isSelected: PropTypes.bool
137142
}
138143

139144
const allowedProps: AllowedPropKeys = [
@@ -149,7 +154,8 @@ const allowedProps: AllowedPropKeys = [
149154
'voiceoverRoleBugWorkaround',
150155
'href',
151156
'elementRef',
152-
'children'
157+
'children',
158+
'isSelected'
153159
]
154160

155161
export type { OptionsItemProps, OptionsItemStyle, OptionsItemRenderProps }

packages/ui-options/src/Options/Item/styles.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ const generateStyle = (
112112
display: 'block',
113113
fontSize: componentTheme.fontSize,
114114
fontFamily: componentTheme.fontFamily,
115-
fontWeight: componentTheme.fontWeight,
115+
fontWeight: props.isSelected
116+
? componentTheme.fontWeightSelected
117+
: componentTheme.fontWeight,
116118
lineHeight: componentTheme.lineHeight,
117119
outline: 'none',
118120
position: 'relative',

packages/ui-options/src/Options/Item/theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const generateComponentTheme = (theme: Theme): OptionsItemTheme => {
4545
fontFamily: typography?.fontFamily,
4646
fontWeight: typography?.fontWeightNormal,
4747
lineHeight: typography?.lineHeightCondensed,
48+
fontWeightSelected: typography?.fontWeightNormal,
4849

4950
color: colors?.contrasts?.grey125125,
5051
background: colors?.contrasts?.white1010,

packages/ui-select/src/Select/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ class Select extends Component<SelectProps> {
425425
// should option be treated as highlighted or selected
426426
if (isSelected) {
427427
optionProps.variant = 'selected'
428+
optionProps.isSelected = true
428429
} else if (isHighlighted) {
429430
optionProps.variant = 'highlighted'
430431
}

0 commit comments

Comments
 (0)