Skip to content

Commit 0af5be6

Browse files
feat: searchbox bordercolor property (#235)
1 parent f1bcfb7 commit 0af5be6

File tree

8 files changed

+35
-11
lines changed

8 files changed

+35
-11
lines changed

SearchBox/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This code component provides a wrapper around the [Fluent UI SearchBox](https://
2020

2121
- **Delay Output** - To delay output by half a second. Useful when input is provided frequently within short duration.
2222

23+
- **Border color** - To define specific color for searchbox border. This exludes onhover & onfocus border color.
24+
2325
## Additional properties
2426

2527
- **Theme** - Accepts a JSON string that is generated using [Fluent UI Theme Designer (windows.net)](https://fabricweb.z5.web.core.windows.net/pr-deploy-site/refs/heads/master/theming-designer/). Leaving this blank will use the default theme defined by Power Apps. Leaving this blank will use the default theme defined by Power Apps. See [theming](theme.md) for guidance on how to configure.

SearchBox/SearchBox/ControlManifest.Input.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest>
33
<control namespace="PowerCAT" constructor="SearchBox" version="0.0.1" display-name-key="SearchBox" description-key="SearchBox_desc" control-type="virtual">
4-
<!--<property name="DefaultValue" display-name-key="SearchBox_DefaultValue" description-key="SearchBox_DefaultValue_Desc" of-type="SingleLine.Text" usage="input"/>-->
54
<property name="SearchText" display-name-key="SearchBox_SearchText" description-key="SearchBox_SearchText_Desc" of-type="SingleLine.Text" usage="bound"/>
65
<property name="Theme" display-name-key="Theme" of-type="Multiple" usage="input" required="false" />
76
<property name="AccessibilityLabel" display-name-key="AccessibilityLabel" of-type="SingleLine.Text" usage="input" required="false" />
@@ -11,6 +10,7 @@
1110
<property name="PlaceHolderText" display-name-key="PlaceHolderText" of-type="SingleLine.Text" usage="input" required="false" default-value="Search" />
1211
<property name="InputEvent" display-name-key="InputEvent" of-type="SingleLine.Text" usage="input" required="false"/>
1312
<property name="DelayOutput" display-name-key="DelayOutput" of-type="TwoOptions" usage="input" required="false" />
13+
<property name="BorderColor" display-name-key="BorderColor" of-type="SingleLine.Text" usage="input" required="false" />
1414
<common-event name="OnChange" />
1515
<feature-usage>
1616
<!-- No common events (OnChange, OnSelect, etc.) are shown unless explicitly declared in the manifest -->

SearchBox/SearchBox/__mocks__/mock-parameters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export function getMockParameters(): IInputs {
1414
InputEvent: new MockStringProperty(),
1515
DelayOutput: new MockTwoOptionsProperty(),
1616
SearchText: new MockStringProperty(),
17+
BorderColor: new MockStringProperty()
1718
};
1819
}

SearchBox/SearchBox/__tests__/__snapshots__/searchbox-lifecycle.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`SearchBox renders 1`] = `
44
<Memo(SearchBoxComponent)
55
ariaLabel=""
6+
borderColor=""
67
disableAnimation={false}
78
disabled={false}
89
height={-1}

SearchBox/SearchBox/components/Component.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export interface ISearchBoxComponentProps {
1010
disabled?: boolean;
1111
disableAnimation?: boolean;
1212
setFocus?: string;
13+
borderColor?: string;
1314
value?: string;
1415
}

SearchBox/SearchBox/components/SearchBox.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import * as React from 'react';
2-
import { SearchBox, createTheme, IPartialTheme, ThemeProvider, IIconProps, mergeStyles } from '@fluentui/react';
2+
import { SearchBox, createTheme, IPartialTheme, ThemeProvider, IIconProps, ISearchBoxStyles } from '@fluentui/react';
33
import { ISearchBoxComponentProps } from './Component.types';
44

55
export const SearchBoxComponent = React.memo((props: ISearchBoxComponentProps) => {
6-
const { onChange, themeJSON, ariaLabel, placeholderText, underLined, disabled, disableAnimation, setFocus, value } =
7-
props;
6+
const {
7+
onChange,
8+
themeJSON,
9+
ariaLabel,
10+
placeholderText,
11+
underLined,
12+
disabled,
13+
disableAnimation,
14+
setFocus,
15+
value,
16+
width,
17+
borderColor,
18+
} = props;
819
const filterIcon: IIconProps = { iconName: props.iconName };
920
const [searchText, setSearchText] = React.useState(value);
1021
const rootRef = React.useRef<HTMLDivElement>(null);
@@ -19,16 +30,19 @@ export const SearchBoxComponent = React.memo((props: ISearchBoxComponentProps) =
1930

2031
React.useEffect(() => {
2132
value !== searchText && setSearchText(value);
22-
}, [value, searchText]);
33+
// eslint-disable-next-line react-hooks/exhaustive-deps
34+
}, [value]);
2335

2436
function onChangeEvent(ev?: React.ChangeEvent<HTMLInputElement>, newValue?: string) {
2537
setSearchText(newValue);
2638
onChange(ev, newValue);
2739
}
2840

29-
const wrapperClass = mergeStyles({
30-
width: props.width,
31-
});
41+
const searchboxStyles = React.useMemo(() => {
42+
return {
43+
root: { width: width, ...(borderColor && { borderColor: borderColor }) },
44+
} as ISearchBoxStyles;
45+
}, [width, borderColor]);
3246

3347
React.useEffect(() => {
3448
if (setFocus && setFocus !== '' && rootRef) {
@@ -38,7 +52,6 @@ export const SearchBoxComponent = React.memo((props: ISearchBoxComponentProps) =
3852
}
3953
}
4054
}, [setFocus, rootRef]);
41-
4255
return (
4356
<ThemeProvider theme={theme}>
4457
<SearchBox
@@ -49,7 +62,7 @@ export const SearchBoxComponent = React.memo((props: ISearchBoxComponentProps) =
4962
iconProps={filterIcon}
5063
disabled={disabled}
5164
disableAnimation={disableAnimation}
52-
className={wrapperClass}
65+
styles={searchboxStyles}
5366
ref={rootRef}
5467
value={searchText}
5568
/>

SearchBox/SearchBox/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
99
private static readonly DELAY_TIMEOUT: number = 500;
1010
context: ComponentFramework.Context<IInputs>;
1111
notifyOutputChanged: ((debounce?: boolean) => void) | null;
12+
notifyOutputChangedNoDebounce: () => void;
1213
searchTextValue: string;
1314
defaultValue: string;
1415
setFocus = '';
@@ -30,6 +31,7 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
3031
*/
3132
public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void): void {
3233
this.notifyOutputChanged = notifyOutputChanged;
34+
this.notifyOutputChangedNoDebounce = notifyOutputChanged;
3335
this.context = context;
3436
this.context.mode.trackContainerResize(true);
3537
if (this.notifyOutputChanged) {
@@ -53,7 +55,7 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
5355
// If the default value is different from searchText value
5456
if (value && this.searchTextValue !== value) {
5557
this.searchTextValue = value;
56-
this.notifyOutputChanged;
58+
this.notifyOutputChangedNoDebounce();
5759
}
5860
}
5961
if (eventChanged && inputEvent.startsWith(InputEvents.SetFocus)) {
@@ -71,6 +73,7 @@ export class SearchBox implements ComponentFramework.ReactControl<IInputs, IOutp
7173
width: allocatedWidth,
7274
height: allocatedHeight,
7375
setFocus: this.setFocus,
76+
borderColor: context.parameters.BorderColor.raw ?? '',
7477
value: this.searchTextValue ?? '',
7578
};
7679

SearchBox/SearchBox/strings/SearchBox.1033.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,7 @@
160160
<data name="SearchBox_DefaultValue_Desc" xml:space="preserve">
161161
<value>Default value to set for the search box. This can be used only once</value>
162162
</data>
163+
<data name="BorderColor" xml:space="preserve">
164+
<value>Border color</value>
165+
</data>
163166
</root>

0 commit comments

Comments
 (0)