Skip to content

Commit 4f4c92b

Browse files
yoshiakishuv1k
authored andcommitted
Fix/docs overflow under project sidebar (#968)
* style: remove unnecessary space * fix: doc's overflow under project sidebar * refactor: remove condition always being true
1 parent e443fdf commit 4f4c92b

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

packages/graphql-playground-react/src/components/Playground/EditorWrapper.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ const GlobalStyle = createGlobalStyle`
807807
box-shadow: none;
808808
margin-left: 0;
809809
position: relative;
810-
z-index: 0;
810+
z-index: 0;
811811
}
812812
813813
.CodeMirror-hint {
@@ -904,8 +904,12 @@ const GraphqlContainer = styled.div`
904904
width: 100%;
905905
`
906906

907-
export const Container = ({ children }) => (
908-
<GraphqlContainer>{children}</GraphqlContainer>
907+
interface Props {
908+
setRef?: (ref: any) => void
909+
}
910+
911+
export const Container: React.SFC<Props> = ({ children, setRef }) => (
912+
<GraphqlContainer ref={setRef}>{children}</GraphqlContainer>
909913
)
910914

911915
export default Wrapper

packages/graphql-playground-react/src/components/Playground/ExplorerTabs/SideTabs.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface Props {
3939
schema: GraphQLSchema
4040
sessionId: string
4141
children: Array<React.ReactElement<any>>
42+
maxWidth: number
4243
}
4344

4445
export interface SideTabContentProps {
@@ -77,7 +78,7 @@ class SideTabs extends React.Component<
7778
const width = this.activeContentComponent.getWidth(props)
7879
this.props.changeWidthDocs(
7980
props.sessionId,
80-
Math.min(width, window.innerWidth - 86),
81+
Math.min(width, this.props.maxWidth),
8182
)
8283
})
8384
}

packages/graphql-playground-react/src/components/Playground/GraphQLEditor.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class GraphQLEditor extends React.PureComponent<Props & ReduxProps> {
139139
private responseResizer: any
140140
private queryVariablesRef
141141
private httpHeadersRef
142+
private containerComponent
142143

143144
componentDidMount() {
144145
// Ensure a form of a schema exists (including `null`) and
@@ -166,7 +167,7 @@ class GraphQLEditor extends React.PureComponent<Props & ReduxProps> {
166167

167168
render() {
168169
return (
169-
<Container>
170+
<Container setRef={this.setContainerComponent}>
170171
<EditorWrapper>
171172
<TopBar
172173
shareEnabled={this.props.shareEnabled}
@@ -264,21 +265,23 @@ class GraphQLEditor extends React.PureComponent<Props & ReduxProps> {
264265
</ResultWrap>
265266
</EditorBar>
266267
</EditorWrapper>
267-
<SideTabs>
268-
<SideTab label="Docs" activeColor="green" tabWidth="49px">
269-
<GraphDocs
270-
schema={this.props.schema}
271-
ref={this.setDocExplorerRef}
272-
/>
273-
</SideTab>
274-
<SideTab label="Schema" activeColor="blue" tabWidth="65px">
275-
<SDLView
276-
schema={this.props.schema}
277-
ref={this.setSchemaExplorerRef}
278-
sessionId={this.props.sessionId}
279-
/>
280-
</SideTab>
281-
</SideTabs>
268+
{this.containerComponent && (
269+
<SideTabs maxWidth={this.containerComponent.offsetWidth - 86}>
270+
<SideTab label="Docs" activeColor="green" tabWidth="49px">
271+
<GraphDocs
272+
schema={this.props.schema}
273+
ref={this.setDocExplorerRef}
274+
/>
275+
</SideTab>
276+
<SideTab label="Schema" activeColor="blue" tabWidth="65px">
277+
<SDLView
278+
schema={this.props.schema}
279+
ref={this.setSchemaExplorerRef}
280+
sessionId={this.props.sessionId}
281+
/>
282+
</SideTab>
283+
</SideTabs>
284+
)}
282285
</Container>
283286
)
284287
}
@@ -330,6 +333,9 @@ class GraphQLEditor extends React.PureComponent<Props & ReduxProps> {
330333
this.schemaExplorerComponent = ref.getWrappedInstance()
331334
}
332335
}
336+
setContainerComponent = ref => {
337+
this.containerComponent = ref
338+
}
333339

334340
handleClickReference = reference => {
335341
if (this.docExplorerComponent) {

0 commit comments

Comments
 (0)