Skip to content

Commit dfd83a5

Browse files
committed
Merge branch 'mpowney-enhancement/258-webPartTitleSectionBackground' into dev
2 parents e3de420 + dda2df4 commit dfd83a5

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/documentation/docs/controls/WebPartTitle.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ The WebPartTitle control can be configured with the following properties:
9393
| updateProperty | Function | yes | Function that you can pass to update the title in the root web part. |
9494
| className | string | no | Optional property to specify a custom class that allows you to change the web part title style. |
9595
| placeholder | string | no | Optional property to specify a custom placeholder to display when the title is editable. |
96-
| moreLink | Function \| JSX.Element | no | Optional property to render a _See all_ link in the web part title. |
96+
| themeVariant | IReadonlyTheme | no | The current loaded SharePoint theme/section background (More info: [Supporting section backgrounds](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/supporting-section-backgrounds)). |
97+
| moreLink | Function \| JSX.Element | no | Optional property to render a _See all_ link in the web part title. |
9798

9899
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/WebPartTitle)

src/controls/webPartTitle/WebPartTitle.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('<WebPartTitle />', () => {
1414
const dummyTitle = "Dummy Title";
1515
const dummyClass = "DummyClass";
1616
const dummyMoreLink = "See all";
17+
const dummyColor = "#ffffff";
1718
const dummyPlaceholder = "News";
1819
const dummyUpdateFnc = sinon.spy((value) => { return value; });
1920

@@ -87,4 +88,11 @@ describe('<WebPartTitle />', () => {
8788
expect(webparttitle.find(`span.${styles.moreLink}`)).to.have.length(0);
8889
done();
8990
});
91+
92+
it('Check theme\'s color is used if specified', (done) => {
93+
webparttitle = mount(<WebPartTitle displayMode={DisplayMode.Edit} title={dummyTitle} updateProperty={dummyUpdateFnc} themeVariant={{ semanticColors: { bodyText: dummyColor }}} />);
94+
expect(webparttitle.find(`div.${styles.webPartTitle}`).prop('style')).property("color").to.equal(dummyColor);
95+
done();
96+
});
97+
9098
});

src/controls/webPartTitle/WebPartTitle.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface IWebPartTitleProps {
1111
className?: string;
1212
placeholder?: string;
1313
moreLink?: JSX.Element | Function;
14+
themeVariant?: any; // TODO: type should be IReadonlyTheme from @microsoft/sp-component-base
1415
}
1516

1617
/**
@@ -43,10 +44,13 @@ export class WebPartTitle extends React.Component<IWebPartTitleProps, {}> {
4344
* Default React component render method
4445
*/
4546
public render(): React.ReactElement<IWebPartTitleProps> {
47+
48+
const color: string = (!!this.props.themeVariant && this.props.themeVariant.semanticColors.bodyText) || null;
49+
4650
if (this.props.title || this.props.moreLink || this.props.displayMode === DisplayMode.Edit) {
4751
return (
4852
<div className={`${styles.webPartHeader} ${this.props.className ? this.props.className : ""}`}>
49-
<div className={styles.webPartTitle}>
53+
<div className={styles.webPartTitle} style={{color: color}}>
5054
{
5155
this.props.displayMode === DisplayMode.Edit && (
5256
<textarea placeholder={this.props.placeholder ? this.props.placeholder : strings.WebPartTitlePlaceholder} aria-label={strings.WebPartTitleLabel} onChange={this._onChange} defaultValue={this.props.title}></textarea>

0 commit comments

Comments
 (0)