Skip to content

Commit

Permalink
Merge pull request #3038 from microsoft-search/fix/1732
Browse files Browse the repository at this point in the history
Remove padding if hide on no result
  • Loading branch information
wobba committed May 28, 2023
2 parents e5bdf3f + 092f30d commit 98a1938
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion search-parts/src/webparts/searchResults/SearchResultsWebPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export default class SearchResultsWebPart extends BaseWebPart<ISearchResultsWebP
let renderRootElement: JSX.Element = null;
let renderDataContainer: JSX.Element = null;

if (this.dataSource) {
if (this.dataSource && this.instanceId) {

// The main content WP logic
renderDataContainer = React.createElement(SearchResultsContainer, {
Expand Down Expand Up @@ -469,6 +469,22 @@ export default class SearchResultsWebPart extends BaseWebPart<ISearchResultsWebP

ReactDom.render(renderRootElement, this.domElement);

if(this.properties.showBlankIfNoResult){
let element = this.domElement.parentElement;
// check up to 3 levels up for padding and exit once found
for (let i = 0; i < 3; i++) {
const style = window.getComputedStyle(element);
const hasPadding = style.paddingTop !== "0px";
if (hasPadding) {
element.style.paddingTop = "0px";
element.style.paddingBottom = "0px";
element.style.marginTop = "0px";
element.style.marginBottom = "0px";
}
element = element.parentElement;
}
}

// This call set this.renderedOnce to 'true' so we need to execute it at the very end
super.renderCompleted();
}
Expand Down

0 comments on commit 98a1938

Please sign in to comment.